留连Django数据库

时间:2010-08-09 04:40:10

标签: python django

我不得不删除我的Django数据库(删除所有表)。现在,当我尝试运行“manage.py syncdb”来重新创建这些表时,我收到消息“Table'user_database.engine.city'不存在”

是否存在告诉djnago这些表仍然存在的文件?

编辑问题:

我不得不删除我的Django数据库(删除所有表)。现在,当我尝试运行“manage.py syncdb”来重新创建这些表时,我收到消息“表'username'database.engine_city'不存在”

Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/home4/username/.local/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home4/username/.local/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home4/username/.local/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home4/username/.local/lib/python2.6/site-packages/django/core/management/base.py", line 209, in execute
translation.activate('en-us')
File "/home4/username/.local/lib/python2.6/site-packages/django/utils/translation/__init__.py", line 66, in activate
return real_activate(language)
File "/home4/username/.local/lib/python2.6/site-packages/django/utils/functional.py", line 55, in _curried
return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
File "/home4/username/.local/lib/python2.6/site-packages/django/utils/translation/__init__.py", line 36, in delayed_loader
return getattr(trans, real_name)(*args, **kwargs)
File "/home4/username/.local/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 193, in activate
_active[currentThread()] = translation(language)
File "/home4/username/.local/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 176, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home4/username/.local/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/home4/username/.local/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home4/username/.local/lib/python2.6/site-packages/massivecoupon/engine/views.py", line 12, in <module>
File "/home4/username/.local/lib/python2.6/site-packages/deals/engine/forms.py", line 40, in <module>
class EmailSubForm(forms.Form):
File "/home4/username/.local/lib/python2.6/site-packages/deals/engine/forms.py", line 42, in EmailSubForm
city                = forms.ChoiceField(initial=1, choices=[ (obj.id, obj.name) for obj in enginemodels.City.objects.all() ])
File "/home4/username/.local/lib/python2.6/site-packages/django/db/models/query.py", line 106, in _result_iter
self._fill_cache()
File "/home4/username/.local/lib/python2.6/site-packages/django/db/models/query.py", line 760, in _fill_cache
self._result_cache.append(self._iter.next())
File "/home4/username/.local/lib/python2.6/site-packages/django/db/models/query.py", line 269, in iterator
for row in compiler.results_iter():
File "/home4/username/.local/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 672, in results_iter
for rows in self.execute_sql(MULTI):
File "/home4/username/.local/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 727, in execute_sql
cursor.execute(sql, params)
File "/home4/username/.local/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "/home4/username/.local/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-x86_64.egg/MySQLdb/cursors.py", line 174, in execute
File "/home4/username/.local/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-x86_64.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
django.db.utils.DatabaseError: (1146, "Table 'username_enjoy.engine_city' doesn't exist")

是否存在告诉djnago这些表仍然存在的文件?

2 个答案:

答案 0 :(得分:2)

在模型验证期间看起来你的largecoupon模块正在进行一些导入,触发交易模块来填充它的缓存。

python中的导入实际上在导入的模块中执行代码,这是编码不良的导入例程的典型案例,具有意想不到的后果

我建议将安装的应用程序列表简化为django基础知识,syncdb,然后开始一次添加一个应用程序,每个应用程序之间都有一个syncdb。

这有望创建导入依赖之前导入该应用程序的表。

祝你好运。

答案 1 :(得分:1)

我刚刚拥有这个,这是因为我的一个模型默认为ModelName.objects.get(id = 1),它需要一个表预先存在。我将其更改为ModelName(id = 1),但没有修复问题。