• Home
  • Jobs
  • Courses
  • Questions
  • Teachers
  • For business
  • ES/EN

0

364
Views
Django migration: django.db.utils.OperationalError: (1824, "Failed to open the referenced table 'classroom_user'")

I am trying to deploy a Django app from a development server to a production server I have set up a virtualenv with python 3.8.10, created the mysql database, I am running in the virtualenv. I get no errors from python manage.py check, get "no changes detected" when running python manage.py makemigrations, but when I run ```python manage.py migrate`` I get the following:

Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying admin.0001_initial...Traceback (most recent call last):...

final line of the traceback:

Django.db.utils.OperationalError: (1824, "Failed to open the referenced table 'classroom_user'")

("classroom" is the name of the app within the project "codex") I just recently rebuilt all of the tables in this database on my development server with no issues.
The database on the production server is empty. models.py is in place and complete. I have tried it both with an empty migrations folder and the migration folder removed. The migration does create django_admin_log, django_content_types, django_migrations, but no other tables.

All of the other posts I have seen on this have been about have foreign key constraints, but in my models.py all of the tables that have foreign keys are specified after the tables where the keys are.

4 months ago ·

Santiago Trujillo

2 answers
Answer question

0

OK, solved.
I was able to get a different error with a slightly older version of Django (3.2.6 instead of 3.2.8) and on a Windows server instead of Linux. This gave me an error regarding foreign key restraints that I have seen in other posts, but was not an error I had seen before.

I had to perform the migrations for my app first (where classroom is the app within the project.):
python manage.py makemigrations classroom
python manage.py migrate

4 months ago · Santiago Trujillo Report

0

This worked for me! Try to check your table ENGINE with this command:

MySQL: SHOW TABLE STATUS WHERE NAME='XXX';

Then find its Engine (It's either MyISAM on InnoDB) After that, change the engine of your newly created table (which throw the error) and match it with your classroom_user table with this command:

MySQL: ALTER TABLE classroom_user ENGINE='XXXX';

Then run migrate again and you're good to go!

4 months ago · Santiago Trujillo Report
Answer question
Find remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.