如何为新服务器运行迁移

时间:2015-06-23 01:47:26

标签: django heroku django-cms django-migrations

我正在尝试在Heroku上部署我的Django-cms网站,而且我真的在努力进行迁移。我正在运行django 1.7.7和django-cms 3.1.0。我没有任何要迁移的数据,所以我只想创建空表。

使用新的Heroku Postgres数据库:

heroku run python manage.py migrate contenttypes

输出:

Operations to perform:
Apply all migrations: contenttypes
Running migrations:
  Applying contenttypes.0001_initial...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 161, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/executor.py", line 68, in migrate
    self.apply_migration(migration, fake=fake)
  File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/executor.py", line 96, in apply_migration
    if self.detect_soft_applied(migration):
  File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/executor.py", line 140, in detect_soft_applied
    apps = project_state.render()
  File "/app/.heroku/python/lib/python3.4/site-packages/django/db/migrations/state.py", line 75, in render
    "for more" % new_unrendered_models
django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<ModelState: 'djangocms_link.Link'>, <ModelState: 'djangocms_text_ckeditor.Text'>, <ModelState: 'djangocms_file.File'>, <ModelState: 'djangocms_inherit.InheritPagePlaceholder'>, <ModelState: 'djangocms_column.MultiColumns'>, <ModelState: 'djangocms_column.Column'>, <ModelState: 'djangocms_googlemap.GoogleMap'>, <ModelState: 'djangocms_flash.Flash'>, <ModelState: 'djangocms_snippet.SnippetPtr'>, <ModelState: 'djangocms_video.Video'>, <ModelState: 'djangocms_teaser.Teaser'>, <ModelState: 'djangocms_picture.Picture'>]
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)
 in an app with no migrations; see https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more

我不明白的是,contenttypes并不依赖于djangocms插件中的任何模型。如果我首先尝试迁移任何插件,我会得到一个堆栈跟踪并且这个:

  

RuntimeError:创建新内容类型时出错。在尝试单独迁移应用之前,请确保迁移了contenttypes。

更新:按照各种django-cms插件的文档,我将MIGRATION_MODULES添加到了settings.py。现在我跑的时候:

heroku run python manage.py makemigrations djangocms_text_ckeditor

创建了迁移:

Migrations for 'djangocms_text_ckeditor':
  0001_initial.py:
    - Create model Text

听起来很棒!但...

heroku run python manage.py migrate djangocms_text_ckeditor

输出:

Operations to perform:
  Apply all migrations: (none)
Running migrations:
  No migrations to apply.
  Your models have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/contenttypes/models.py", line 44, in get_for_model
    ct = self._get_from_cache(opts)
  File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/contenttypes/models.py", line 34, in _get_from_cache
    return self.__class__._cache[self.db][key]
KeyError: 'default'

During handling of the above exception, another exception occurred:
[long stack trace ommitted]

1 个答案:

答案 0 :(得分:1)

djangocms_link模块文档中所述 - https://github.com/divio/djangocms-link

  
    

如果使用Django 1.7将'djangocms_link':'djangocms_link.migrations_django'添加到MIGRATION_MODULES

  

同样适用于djangocms_file模块

所以基本上你应该在你的settings.py

MIGRATION_MODULES = {
     'djangocms_link': 'djangocms_link.migrations_django',
     'djangocms_file': 'djangocms_file.migrations_django'
}