Django postgres“无迁移应用”故障排除

rjee0c15  于 2023-01-10  发布在  Go
关注(0)|答案(1)|浏览(118)

我不得不修改我的应用程序的表,所以我从postgres数据库中删除了它(在django python shell中使用objectname.objects.all().delete(),在PGAdmin中使用postgres)。
我删除了appname migrations文件夹。当我运行python manage.py makemigrations appname时,文件夹迁移是用0001_initial.py创建表的。当我运行python manage.py migrate appname时,什么也没发生,我在postgres PGAdmin中看不到表。

(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.

当我删除文件夹migrations时,我可以看到迁移与python manage.py showmigrations一起消失了。
我也尝试了python manage.py migrate --run-syncdb,但仍然没有结果。

(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.

关于可能发生的事情有什么其他的想法吗?也许postgres的full_text_search索引搞砸了?关于如何在postgres中重新获得表有什么想法吗?

72qzrwbm

72qzrwbm1#

您是否尝试过python manage.py migrate appname zero?它将迁移到在应用中创建任何模型之前的状态。https://docs.djangoproject.com/en/4.1/topics/migrations/#reversing-migrations

相关问题