[英]How do I re-create databases after they were deleted?
I used the python manage.py makemigrations myApp
and python manage.py migrate myApp
commands to create Postgres tables in my database. 我用了python manage.py makemigrations myApp
和python manage.py migrate myApp
命令在我的数据库中创建的Postgres表。 Then someone manually deleted them with SQL queries. 然后有人用SQL查询手动删除了它们。
Can I re-create these tables, without data, using terminal commands? 我可以使用终端命令重新创建这些没有数据的表吗?
It depends. 这取决于。
Did they delete all of the tables? 他们是否删除了所有表格? If so thats easy. 如果是这样,那很容易。 Just rerun the 只需重新运行
manage.py migrate.
Did they only delete new tables that you have added with migrations? 他们只是删除您在迁移中添加的新表吗? Not so bad, go into the django_migrations table, and delete the entries for the migrations that created the deleted tables from that table and rerun 还不错,进入django_migrations表,并删除从该表创建已删除表的迁移条目,然后重新运行
manage.py migrate.
When you run makemigrations, Django creates the migration file but doesn't do anything with it in terms of touching the database. 当您运行makemigrations时,Django会创建迁移文件,但是就触摸数据库而言,它不执行任何操作。
When you run the migrate command, Django runs the alter table commands on the database and adds an entry to the django_migrations table, so it knows which migrations have been done, and which still need to be run. 当您运行migration命令时,Django在数据库上运行alter table命令,并将条目添加到django_migrations表中,因此它知道哪些迁移已完成,哪些迁移仍需要运行。
If the person has deleted a random set of tables that are out of sync with your migrations its going to be a mess and its going to involve a lot of manual work to make sure your migrations and database tables are in sync. 如果该人删除了与您的迁移不同步的随机表集,那将是一团糟,并且将涉及大量手动工作以确保您的迁移和数据库表是同步的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.