我正在使用django 1.3和python 2.4进行大规模项目。我决定将它更新为django 1.9和python 2.7。
由于django_admin的sql参数在1.9中被折旧,因此更新数据库创建方法发生了很大变化。
我正在使用命令:
python /usr/local/django/<project>/manage.py migrate --fake-initial --noinput --run-syncdb
用于创建表。但我的表格未创建,管理正在打印此错误。
Traceback (most recent call last):
File "/src/project/project-export/django/projectadmin/manage.py", line 13, in <module>
execute_from_command_line(sys.argv)
File "/opt/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/opt/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/python/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/python/lib/python2.7/site-packages/django/core/management/base.py", line 398, in execute
self.check()
File "/opt/python/lib/python2.7/site-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/opt/python/lib/python2.7/site-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/opt/python/lib/python2.7/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/opt/python/lib/python2.7/site-packages/django/core/checks/urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "/opt/python/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/opt/python/lib/python2.7/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/opt/python/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/opt/python/lib/python2.7/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/opt/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/local/django/projectadmin/projectadmin/urls.py", line 4, in <module>
import projectadmin.views
File "/usr/local/django/projectadmin/projectadmin/views.py", line 20, in <module>
from projectadmin.forms import UserCreationForm
File "/usr/local/django/projectadmin/projectadmin/forms.py", line 252, in <module>
class UserCreationForm(forms.ModelForm):
File "/usr/local/django/projectadmin/projectadmin/forms.py", line 256, in UserCreationForm
template_choice = form_utils.create_template_choices_field()
File "/usr/local/django/projectadmin/projectadmin/form_utils.py", line 15, in create_template_choices_field
choices = [(x.id, x.template_name) for x in all_templates]
File "/opt/python/lib/python2.7/site-packages/django/db/models/query.py", line 258, in __iter__
self._fetch_all()
File "/opt/python/lib/python2.7/site-packages/django/db/models/query.py", line 1074, in _fetch_all
self._result_cache = list(self.iterator())
File "/opt/python/lib/python2.7/site-packages/django/db/models/query.py", line 52, in __iter__
results = compiler.execute_sql()
File "/opt/python/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 848, in execute_sql
cursor.execute(sql, params)
File "/opt/python/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/opt/python/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/opt/python/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/opt/python/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 112, in execute
return self.cursor.execute(query, args)
File "/opt/python/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/opt/python/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.ProgrammingError: (1146, "Table 'project.projectadmin_usertemplate' doesn't exist")
错误中没有与表创建相关的内容。它抱怨丢失了表但没有创建它。
我怀疑INSTALLED_APPS
不包含我的表格,但我已将我的申请表附加到settings.py
的列表中。
我怀疑我需要将我的应用程序单独添加到installed_apps
列表中。
我在更新系统时遵循了django本身的推荐程序。
如果我的怀疑是真的,我怎么能在安装的应用程序中添加模型,或者任何其他建议会很棒?
答案 0 :(得分:0)
感谢django-user邮件列表,我发现我的问题是在创建之前尝试引用一个尚未创建的表。 &#34;在开始应用迁移之前,Django 需要导入所有包,以便它可以确定什么 需要应用的迁移。但是,在导入过程中 它们,您已经在对这些表执行数据库查询。&#34; 将这些引用字段放入try catch块中捕获异常&#34; ProgrammingError&#34;解决了我的问题。