简体   繁体   English

Django - 关系“关系”不存在。 无法运行python manage.py migrate?

[英]Django - Relation “relation” does not exist. Cannot run python manage.py migrate?

So I was being stupid and I went to delete one of the tables in my django app so opened up psql and ran "Drop table ;" 所以我是愚蠢的,我去删除我的django应用程序中的一个表,所以打开了psql并运行“Drop table;” and dropped the table. 然后放下桌子。 Then I deleted my model and ran "python manage.py migrate" and I get this error... 然后我删除了我的模型并运行“python manage.py migrate”,我收到此错误...

django.db.utils.ProgrammingError: relation "textchange_myuser" does not exist

among other stuff above it. 在它上面的其他东西。

So now I can't delete the table properly and I can't get it back. 所以现在我无法正确删除表格,我无法取回它。 What do I do? 我该怎么办?

Thanks. 谢谢。

As per my comment, in your situation you might run: 根据我的评论,在您的情况下,您可能会运行:

python manage.py migrate yourapp --fake

to "fake" applying the migration but not actually alter your database. “假”应用迁移但实际上并没有改变你的数据库。

You can read more HERE 你可以在这里阅读更多内容

Hope this helps. 希望这可以帮助。

I deleted a table from postgres and then django was unable to detect the change. 我从postgres删除了一个表,然后django无法检测到更改。 I tried everything but django didn't created a new table. 我尝试了一切,但是django没有创建一个新表。 Finally I fixed this with some alternate way. 最后我用另一种方法解决了这个问题。

login to your database create table manually. 手动登录数据库创建表。 - Get the create command from django itself. - 从django本身获取create命令。

python manage.py sqlmigrate 'yourapp' 001

this will give you the initial command django used to create the table. 这将为您提供用于创建表的初始命令django。

one by one get all the migrations and execute commands on database by command line. 逐个获取所有迁移并通过命令行在数据库上执行命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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