将django站点移动到另一台服务器

时间:2013-01-21 09:03:36

标签: django syncdb

我想将我的django网站移动到另一台机器上。 (我想从空DB开始)
我以为我将完成以下步骤。

  • 复制所有文件

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

    运行syncdb

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

我尝试了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")

1 个答案:

答案 0 :(得分:3)

ALBUM_IMAGE_TYPE = ContentType.objects.get(app_label =&#34; gallery&#34;,model =&#34; AlbumImage&#34;)

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

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