django.db.utils.ProgrammingError: table does not exist after migrating to Postgres from SQLite
django.db.utils.ProgrammingError: table does not exist after migrating to Postgres from SQLite
更改我的设置并迁移到 Postgres 后,我在执行时遇到此错误
迁移,我之前删除了所有迁移文件夹,因为我遇到了与 数据库不一致 类似的问题,现在我的应用程序级目录中没有任何迁移,我有 DB 备份但是,我该如何解决这个问题,感谢任何帮助,在此先感谢
数据库设置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'mypass',
'HOST': 'localhost',
'PORT': '5432',
}
}
跟踪
Traceback (most recent call last):
File "C:\Users\atifs\Documents\food_deliveryapp\fooddelivery\manage.py", line 22, in <module>
main()
File "C:\Users\atifs\Documents\food_deliveryapp\fooddelivery\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\commands\migrate.py", line 244, in handle
post_migrate_state = executor.migrate(
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\migrations\executor.py", line 230, in apply_migration
migration_recorded = True
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\backends\base\schema.py", line 118, in __exit__
self.execute(sql)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\backends\base\schema.py", line 145, in execute
cursor.execute(sql, params)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\backends\utils.py", line 98, in execute
return super().execute(sql, params)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\backends\utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "customers_user" does not exist
正如 V.D 所说,我错误地删除了应用程序中的所有迁移文件夹,我不得不使用 init.py 重新创建这些文件夹,然后 运行 迁移,问题现已解决
更改我的设置并迁移到 Postgres 后,我在执行时遇到此错误 迁移,我之前删除了所有迁移文件夹,因为我遇到了与 数据库不一致 类似的问题,现在我的应用程序级目录中没有任何迁移,我有 DB 备份但是,我该如何解决这个问题,感谢任何帮助,在此先感谢
数据库设置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'mypass',
'HOST': 'localhost',
'PORT': '5432',
}
}
跟踪
Traceback (most recent call last):
File "C:\Users\atifs\Documents\food_deliveryapp\fooddelivery\manage.py", line 22, in <module>
main()
File "C:\Users\atifs\Documents\food_deliveryapp\fooddelivery\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\commands\migrate.py", line 244, in handle
post_migrate_state = executor.migrate(
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\migrations\executor.py", line 230, in apply_migration
migration_recorded = True
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\backends\base\schema.py", line 118, in __exit__
self.execute(sql)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\backends\base\schema.py", line 145, in execute
cursor.execute(sql, params)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\backends\utils.py", line 98, in execute
return super().execute(sql, params)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\backends\utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "customers_user" does not exist
正如 V.D 所说,我错误地删除了应用程序中的所有迁移文件夹,我不得不使用 init.py 重新创建这些文件夹,然后 运行 迁移,问题现已解决