Django数据库迁移错误(sqlite3->;postgre)
我已经使用django创建了一个应用程序,现在我尝试使用另一个数据库,而不是它的默认数据库sqlite3。我选择了博士后 当我运行命令时Django数据库迁移错误(sqlite3->;postgre),django,postgresql,sqlite,django-migrations,Django,Postgresql,Sqlite,Django Migrations,我已经使用django创建了一个应用程序,现在我尝试使用另一个数据库,而不是它的默认数据库sqlite3。我选择了博士后 当我运行命令时 python3 manage.py makemigrations 我得到以下错误: Traceback (most recent call last): File "/root/mypro/env/lib/python3.5/site-packages/django/db/backends/utils.py", line
python3 manage.py makemigrations
我得到以下错误:
Traceback (most recent call last):
File "/root/mypro/env/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "banners_supercat" does not exist
LINE 1: ...supercat"."id", "banners_supercat"."english" FROM "banners_s...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
....
File "/root/mypro/banners/urls.py", line 2, in <module>
from . import views
File "/root/mypro/banners/views.py", line 13, in <module>
from .forms import (GoodBaseFormEn, GoodBaseFormFa, CreateSelectField, CreateFormDyn,
File "/root/mypro/banners/forms.py", line 190, in <module>
class CreateSearchFormDynEn(forms.Form):
File "/root/mypro/banners/forms.py", line 191, in CreateSearchFormDynEn
supercat = forms.ChoiceField(required=False, choices=[('',' ')]+getAllSuperCats(cv.I_EN), label='Category')
File "/root/mypro/banners/queryfuncs.py", line 59, in getAllSuperCats
return list(SuperCat.objects.all().values_list('id',('farsi', 'english')[lan]))
File "/root/mypro/env/lib/python3.5/site-packages/django/db/models/query.py", line 272, in __iter__
self._fetch_all()
File "/root/mypro/env/lib/python3.5/site-packages/django/db/models/query.py", line 1179, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/root/mypro/env/lib/python3.5/site-packages/django/db/models/query.py", line 138, in __iter__
return compiler.results_iter(tuple_expected=True, chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/root/mypro/env/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1019, in results_iter
results = self.execute_sql(MULTI, chunked_fetch=chunked_fetch, chunk_size=chunk_size)
File "/root/mypro/env/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1068, in execute_sql
cursor.execute(sql, params)
...
File "/root/mypro/env/lib/python3.5/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/root/mypro/env/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "banners_supercat" does not exist
LINE 1: ...supercat"."id", "banners_supercat"."english" FROM "banners_s...
回溯(最近一次呼叫最后一次):
文件“/root/mypro/env/lib/python3.5/site packages/django/db/backends/utils.py”,第85行,在
返回self.cursor.execute(sql,params)
psycopg2.ProgrammingError:关系“banners\u supercat”不存在
第1行:…超级猫“.id”,“banners\u supercat”,“english”来自“banners\u s…”。。。
^
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
....
文件“/root/mypro/banners/url.py”,第2行,在
从…起导入视图
文件“/root/mypro/banners/views.py”,第13行,在
from.forms导入(GoodBaseFormEn、GoodBaseFormFa、CreateSelectField、CreateFormDyn、,
文件“/root/mypro/banners/forms.py”,第190行,在
类CreateSearchFormDynEn(forms.Form):
CreateSearchFormDynEn中的文件“/root/mypro/banners/forms.py”,第191行
supercat=forms.ChoiceField(必选项=False,选项=[('',)]+GetAllSupercat(cv.I_EN),标签为class='Category')
getAllSuperCats中的文件“/root/mypro/banners/queryfuncs.py”,第59行
返回列表(SuperCat.objects.all()
文件“/root/mypro/env/lib/python3.5/site packages/django/db/models/query.py”,第272行,在__
self._fetch_all()
文件“/root/mypro/env/lib/python3.5/site packages/django/db/models/query.py”,第1179行,全部
self.\u result\u cache=list(self.\u iterable\u class(self))
文件“/root/mypro/env/lib/python3.5/site packages/django/db/models/query.py”,第138行,在__
返回compiler.results\u iter(tuple\u expected=True,chunked\u fetch=self.chunked\u fetch,chunk\u size=self.chunk\u size)
结果文件中的文件“/root/mypro/env/lib/python3.5/site packages/django/db/models/sql/compiler.py”,第1019行
results=self.execute\u sql(MULTI,chunked\u fetch=chunked\u fetch,chunk\u size=chunk\u size)
文件“/root/mypro/env/lib/python3.5/site packages/django/db/models/sql/compiler.py”,第1068行,在execute\u sql中
cursor.execute(sql,params)
...
文件“/root/mypro/env/lib/python3.5/site packages/django/db/utils.py”,第89行,在__
使用exc_值的_回溯(回溯)提高dj_exc_值
文件“/root/mypro/env/lib/python3.5/site packages/django/db/backends/utils.py”,第85行,在
返回self.cursor.execute(sql,params)
django.db.utils.ProgrammingError:关系“banners\u supercat”不存在
第1行:…超级猫“.id”,“banners\u supercat”,“english”来自“banners\u s…”。。。
有什么问题?我该怎么办?试试这个
运行python manage.py inspectdb
它将显示迁移的模型,并将其与models.py进行比较
使models.py与inspectdb结果相同
那之后呢
python manage.py makemigrations
python manage.py migrate --fake <migrationfile_number> (eg:0002)
它将解决迁移问题…试试这个
运行python manage.py inspectdb
它将显示迁移的模型,并将其与models.py进行比较
使models.py与inspectdb结果相同
那之后呢
python manage.py makemigrations
python manage.py migrate --fake <migrationfile_number> (eg:0002)
它将解决迁移问题…你能分享你的模型吗?你能分享你的模型吗?我执行了
inspectdb
命令,但它给了我一个命令:#这是一个自动生成的Django模型模块。#你必须手动执行以下操作来清理:#重新排列模型的顺序#确保每个模型都有一个带有primary_key=True的字段#*确保每个ForeignKey的on_delete设置为所需的行为。#*如果希望允许Django创建、修改和删除表,请删除managed=False行#可以随意重命名模型,但不要重命名db_表值或字段名。从Django.db导入模型
我做了检查b
命令,但它给了我以下命令:#这是一个自动生成的Django模型模块。#您必须手动执行以下操作来清理此模块:#*重新排列模型的顺序#*确保每个模型都有一个主_key=True的字段#*确保每个ForeignKey都将on_delete设置为所需的行为。#*删除托管=False行如果您希望允许Django创建、修改和删除表,请随意重命名模型,但不要重命名db#U表值或字段名。从Django.db导入模型