我在SQlite上做了我的django开发,现在我试图用postgres 9.5来运行我的应用程序。
然而,当我运行迁移时,我收到此错误 django.db.utils.ProgrammingError:关系“django_content_type”不存在
。我正在使用django 1.8和python 2.7并在进行迁移时获取它,当运行-fake initial得到相同的错误时。
我正在查看现有的答案(这个问题很常见),但我没有看到对我有用的明确答案。
> (mrp) C:\Users\I812624\dev\mrp\src>python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: django_filters, autofixture, staticfiles, message
s, smart_selects, watson, django_select2, django_countries, mptt, psycopg2, main
, crispy_forms
Apply all migrations: customer, manufacture, product, vendor, purchase, admin,
sessions, sales, flatpages, sites, item, contenttypes, production, auth, regist
ration, inventory
Synchronizing apps without migrations:
Creating tables...
Creating table watson_searchentry
Running deferred SQL...
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\__init
__.py", line 338, in execute_from_command_line
utility.execute()
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\__init
__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\base.p
y", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\base.p
y", line 441, in execute
output = self.handle(*args, **options)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\comman
ds\migrate.py", line 179, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\core\management\comman
ds\migrate.py", line 317, in sync_apps
cursor.execute(statement)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\utils.py",
line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\utils.py",
line 64, in execute
return self.cursor.execute(sql, params)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\utils.py", line 97,
in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\I812624\dev\mrp\lib\site-packages\django\db\backends\utils.py",
line 62, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "django_content_type" does not exist
答案 0 :(得分:1)
settings.py中的DATABASES部分应该是:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'yourdb',
'USER': 'youruser',
'PASSWORD': 'yourpass',
'HOST': '',
},
}
您的INSTALLED_APPS应包含psycopg2 一旦到位并重新启动服务器,您就可以重新启动,这应该创建缺少的表
答案 1 :(得分:0)
应自动创建django_content_type。 我想知道你是如何做你的makemigrations的 也许试试
python manage.py makemigrations
而不是一个一个地执行
答案 2 :(得分:0)
所以在玩完之后就开始工作了。 解决方案是我没有将服务器添加到pgAdmin https://www.pgadmin.org/
我假设pgadmin只是一个工具,可以看到最新情况,但是没有将postgre添加到pgadmin,迁移有错误。