我正在尝试将现有数据库导入到我的 Django 项目中,因此我运行python manage.py migrate --fake-initial
,但出现此错误:
operations to perform:
Apply all migrations: ExcursionsManagerApp, GeneralApp, InvoicesManagerApp, OperationsManagerApp, PaymentsManagerApp, RatesMan
agerApp, ReportsManagerApp, ReservationsManagerApp, UsersManagerApp, admin, auth, authtoken, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... FAKED
Applying auth.0001_initial... FAKED
Applying contenttypes.0002_remove_content_type_name... OK
Applying GeneralApp.0001_initial...Traceback (most recent call last):
File "/Users/hugovillalobos/Documents/Code/IntellibookWebProject/IntellibookWebVenv/lib/python3.6/site-packages/django/db/back
ends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
psycopg2.ProgrammingError: relation "GeneralApp_airport" already exists
当然所有的表都已经存在于数据库中,这就是为什么我使用--fake-initial
的原因,该原因应该伪造创建数据库对象。
为什么migrate
试图创建表GeneralApp__airport
而不是伪造它?
答案 0 :(得分:0)
您可以按照以下步骤从现有数据库进行迁移。首先从数据库中清空django迁移表。
delete from django_migrations
rm -rf <app>/migrations/
python manage.py migrate --fake
python manage.py makemigrations <app>
python manage.py migrate --fake-initial
答案 1 :(得分:0)
只需运行以下command即可解决问题:
{{1}}