Reputation: 315
Using PostgresSQL and Django, I dropped two tables from postgresql manually.
drop table ...
Then I did make migrations
and migrate
.
But my tables are not recreated. Can not access from shell_plus. Also in this page, django return relation 'table name' does not exists.
I want to makemigrations and migrate to create tables again.
How can I solve my issue ?
Upvotes: 3
Views: 1635
Reputation: 161
It depends on your current migrations files tree structure.
If your migration file containing CreateModel
for those tables you deleted directly from PostgreSQL are the leaf nodes, i.e, there was no other migration file after that, you can simply delete the entry of the migration file in the django_migrations
table and run migrate.
For example,
app/migrations/0002_20210813_122.py is the file having commands for the creation of your tables, and this is the last node ( how do we know if this is the last file? so you just check if there's any other migration file in your project which has this filename 0002_20210813_122
under its dependencies field, if no then this file is the leaf node ). If it's a leaf node, go to django_migrations
table in your database and delete an entry with value 0002_20210813_122
under column name
and column app
should be your app_name
.
Now run python manage.py migrate
, the tables will be recreated.
If your migration file isn't a leaf node, then kindly share the tree structure of your migrations file, for us to help you out.
Upvotes: 3