简体   繁体   English

删除数据库后如何重新创建数据库?

[英]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 myApppython 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.

相关问题 如何为pandas.tseries.holiday.USFederalHolidayCalendar重新创建日历规则? - How do I re-create the calendar rules for pandas.tseries.holiday.USFederalHolidayCalendar? 如何使用代理参数重新创建 pysftp.Connection? - How do I re-create pysftp.Connection with a proxy parameter? 如何使用 python etree 重新创建此 XML 代码? - How can I re-create this XML code using python etree? 如何从熊猫数据帧创建可复制和粘贴的文本,以重新创建相同的数据帧,包括索引? - From a pandas DataFrame, how can I create copy-and-pasteable text that will re-create the same DataFrame, including the index? ElasticSearch 删除并重新创建索引 - ElasticSearch Delete and re-Create Index 在计算完增量但没有更改后,无法重新创建累积系列。 为什么? - Unable to Re-Create Cumulative Series, After Calculating Incremental But Making No Changes. Why? 如何使用相同的输入参数创建不重新创建 object 的 class - How to create a class that doesn't re-create an object with identical input parameters 如何从已知的系数/参数重新创建 ARIMA model - How to re-create a ARIMA model from already known coefficients/parameters 应该如何在 python tkinter 中删除由循环创建的小部件? - How should be deleted widgets that were create by a loop, in python tkinter? 在服务器运行时重新创建SQLAlchemy对象是否安全? - Is it safe to re-create a SQLAlchemy object while server is running?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM