3

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 ?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your help. This answer is really clear to understand what I done and what should I worry about. Deleting the last migration file and makemigrations app_name&migrate is solved my issue. Of course I checked dependicies before did that :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.