简体   繁体   中英

How to create table with migrate after drop table from postgresql in django?

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?

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, ie, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM