英文:
Django postgres "No migrations to apply" troubleshoot
问题
我不明白为什么在删除应用的migrations
文件夹后,运行python manage.py migrate appname
没有任何反应,并且在Postgres PGAdmin中看不到表格。
你可能想尝试以下几种方法来解决这个问题:
-
确保你已经运行了
makemigrations
命令,并且没有出现错误。你可以运行以下命令来生成迁移文件:python manage.py makemigrations appname
-
如果你已经生成了迁移文件并且没有错误,尝试运行
migrate
命令,但不指定应用程序名称,以确保所有应用程序的迁移都被应用:python manage.py migrate
-
如果仍然没有成功,尝试使用
--fake
选项来模拟应用迁移:python manage.py migrate appname --fake
这将标记迁移为已应用,即使它们似乎没有被应用。
-
如果你认为全文搜索索引可能导致问题,请尝试将该索引从模型中移除,并运行迁移。然后再次添加索引。
-
最后,确保你的数据库连接配置正确,以便Django可以正确连接到Postgres数据库。
希望这些建议能帮助你解决问题并恢复表格到Postgres数据库中。如果问题仍然存在,请提供更多详细信息,以便更好地帮助你解决问题。
英文:
I had to modify the table of my app so I dropped it from postgres database (using objectname.objects.all().delete()
in django python shell and with postgres at PGAdmin).
I deleted the appname migrations
folder. When I run python manage.py makemigrations appname
, the folder migrations gets created with a 0001_initial.py
creating the tables.
When I run python manage.py migrate appname
, nothing happens and I cannot see the tables in postgres PGAdmin.
(website) C:\Users\Folder>python manage.py makemigrations appname
Migrations for 'appname':
food\migrations(website) C:\Users\Folder>python manage.py makemigrations appname
Migrations for 'appname':
food\migrations\0001_initial.py
- Create model Table1
- Create model Table2
- Create index Table2_search__7dd784_gin on field(s) search_vector of model Table2
(website) C:\Users\Folder>python manage.py migrate
Operations to perform:
Apply all migrations: accounts, admin, auth, contenttypes, appname, sessions
Running migrations:
No migrations to apply.
01_initial.py
- Create model Table1
- Create model Table2
- Create index Table2_search__7dd784_gin on field(s) search_vector of model Table2
(website) C:\Users\Folder>python manage.py migrate
Operations to perform:
Apply all migrations: accounts, admin, auth, contenttypes, appname, sessions
Running migrations:
No migrations to apply.
When I deleted the folder migrations I can see the migrations are gone with python manage.py showmigrations
.
I also tried python manage.py migrate --run-syncdb
but still no result.
(website) C:\Users\Folder>python manage.py migrate --run-syncdb
Operations to perform:
Synchronize unmigrated apps: messages, postgres, staticfiles
Apply all migrations: accounts, admin, auth, contenttypes, appname, sessions
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Running migrations:
No migrations to apply.
Any other idea on what may be happening? Maybe postgres full_text_search index is messing it up?
Any idea on how to get the tables in postgres again?
答案1
得分: 1
你尝试过 python manage.py migrate appname zero
吗?
它会将应用程序中创建任何模型之前的状态迁移。
https://docs.djangoproject.com/en/4.1/topics/migrations/#reversing-migrations
英文:
Have you tried python manage.py migrate appname zero
?
It will migrate to the state before creating any models in the app.
https://docs.djangoproject.com/en/4.1/topics/migrations/#reversing-migrations
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论