I accidentally manually dropped a data table. Now when I try to run my project I get an error that says: 1051 Unknown table error. Is there any way I can fix it it or am I screwed?
-
try `python manage.py migrate` – gogaz Aug 27 '18 at 11:52
-
I did try it, and I get the same error. – Keselme Aug 27 '18 at 11:57
-
This have happened in production database ? – Umair Mohammad Aug 27 '18 at 12:03
-
mysqlcheck --auto-repair --databases gonegr_db --user=your_username --password – Marin Aug 27 '18 at 12:11
-
Possible duplicate of [Table was deleted, how can I make Django recreate it?](https://stackoverflow.com/questions/33259477/table-was-deleted-how-can-i-make-django-recreate-it) – Ivan Starostin Aug 27 '18 at 12:26
2 Answers
If you don't mind. Goto your app folders and delete all migration files. Delete all tables in the DB. then run migrations and migrate all over again to get your DB refreshed.
OR post the full error message you are getting..

- 110
- 1
- 11
if you faced that same error.that error show because you made changes like creating, deleting, or updating a manual mistake in direct Database or PHPMyAdmin. then this error show like
MySQLdb._exceptions.ProgrammingError: (1146, "Table 'table name' doesn't exist"
in my case, I manually deleted the table in PHPMyAdmin. solution of error: You directly add the table in PHPMyAdmin and then delete all migration in project_app and add the table class in the model.py file
python manage.py makemigrations
o/p: No migrations to apply.
python manage.py migrate
o/p: No changes detected
then remove a table in the Model.py file
python manage.py makemigrations
o/p: No migrations to apply.
python manage.py migrate
o/p: No changes detected
then Add Table Class in the Model.py file
python manage.py makemigrations
o/p: Applying migrations
python manage.py migrate
o/p: Create model TableName
definitely you solve this error

- 78
- 6