0

我想将我的 django 站点移动到另一台机器上。(我想从空数据库开始)
我想我会完成以下步骤。

  • 复制所有文件

    设置所有工具(django、python、..等)

    运行同步数据库

当我运行时manage.py syncdb,它抱怨某些表(例如 django_content_type)不存在。
我查看了数据库,数据库中确实没有表。

我试过recreate project(startproject)或recreate app(startapp)。(但他们失败了,因为项目或应用程序名称已被占用。)

我应该怎么办?
我能想到的原因是mysql升级到5.5.27(默认为innodb)


$ python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/core/management/base.py", line 231, in execute
    self.validate()
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/core/management/base.py", line 266, in validate
    num_errors = get_validation_errors(s, app)
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/core/management/validation.py", line 30, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/db/models/loading.py", line 158, in get_app_errors
    self._populate()
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/db/models/loading.py", line 64, in _populate
    self.load_app(app_name, True)
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/db/models/loading.py", line 88, in load_app
    models = import_module('.models', app_name)
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/ubuntu/Documents/aLittleArtist/django/gallery/models.py", line 152, in <module>
    ALBUM_IMAGE_TYPE = ContentType.objects.get(app_label="gallery", model="AlbumImage")
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/db/models/manager.py", line 131, in get
    return self.get_query_set().get(*args, **kwargs)
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/db/models/query.py", line 361, in get
    num = len(clone)
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/db/models/query.py", line 85, in __len__
    self._result_cache = list(self.iterator())
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/db/models/query.py", line 291, in iterator
    for row in compiler.results_iter():
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 763, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 818, in execute_sql
    cursor.execute(sql, params)
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/db/backends/util.py", line 40, in execute
    return self.cursor.execute(sql, params)
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 114, in execute
    return self.cursor.execute(query, args)
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 174, in execute
    self.errorhandler(self, exc, value)
  File "/home/ubuntu/virtualenvs/aLittleArtist/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
django.db.utils.DatabaseError: (1146, "Table 'gallery_db.django_content_type' doesn't exist")
4

1 回答 1

3

ALBUM_IMAGE_TYPE = ContentType.objects.get(app_label="gallery", model="AlbumImage")

这条线是罪魁祸首。
似乎上面的行尝试在创建任何数据库表之前进行数据库查询。

我删除了该行和相关代码并让syncdb运行。并确实与南方迁移。

于 2013-01-21T10:39:31.217 回答