【问题标题】:Migration error with Django 1.7.1Django 1.7.1 的迁移错误
【发布时间】:2015-01-31 09:14:21
【问题描述】:

在引入新应用 (django-allauth) 后执行迁移时出现错误。我不确定还可以尝试什么来修复错误。我尝试了一些方法,但不幸的是它们似乎没有帮助。

运行ma​​nage.py migrate时:

File "D:\Python27\Lib\site-packages\django\db\migrations\state.py", line 71, 
in render raise     
InvalidBasesError("Cannot resolve bases for %r\nThis can happen if you are inheriting 
models from an app with migrations (e.g. contrib.auth)\n in an app with no migrations; 
see https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more" % 
new_unrendered_models)
django.db.migrations.state.InvalidBasesError: Cannot resolve bases for 
[<ModelState: 'blog.BlogPage'>, <ModelState: 'blog.BlogIndexPage'>]
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

models.py

    from django.db import models
    from wagtail.wagtailcore.models import Page, Orderable
    from wagtail.wagtailcore.fields import RichTextField
    from wagtail.wagtailadmin.edit_handlers import FieldPanel  ,MultiFieldPanel,InlinePanel, PageChooserPanel
    from modelcluster.fields import ParentalKey

class BlogPage(Page):
    body = RichTextField()
    date = models.DateField("Post date")
    indexed_fields = ('body', )
    search_name = "Blog Page"

BlogPage.content_panels = [
    FieldPanel('title', classname="full title"),
    FieldPanel('date'),
    FieldPanel('body', classname="full"),
]


class LinkFields(models.Model):
    link_page = models.ForeignKey(
        'wagtailcore.Page',
        null=True,
        blank=True,
        related_name='+'
    )

panels = [
    PageChooserPanel('link_page'),
]

class Meta:
    abstract = True

class RelatedLink(LinkFields):
    title = models.CharField(max_length=255, help_text="Link title")
    panels = [
         FieldPanel('title'),
         MultiFieldPanel(LinkFields.panels, "Link"),
     ]

     class Meta:
         abstract = True


 class BlogIndexPageRelatedLink(Orderable, RelatedLink):
     page = ParentalKey('blog.BlogIndexPage', related_name='related_links')

 class BlogIndexPage(Page):
     intro = models.CharField(max_length=256)
     indexed_fields = ('body', )
     search_name = "Blog Index Page"

 BlogIndexPage.content_panels = [
     FieldPanel('title', classname="full title"),
     FieldPanel('intro', classname="full"),
     InlinePanel(BlogIndexPage, 'related_links', label="Related links"),
 ]    

到目前为止我所尝试的:

  1. 听从了这里的建议:https://stackoverflow.com/a/25858659 但是这对我来说并没有改变任何东西。
  2. 我也试过https://code.djangoproject.com/ticket/22051#comment:12,但没有成功。

注意: makemigrations 运行(未检测到更改)但迁移失败。

平台设置:目前在 Windows 机器上的 Django 1.7.1 上。 django-allauth 在这个盒子上的其他应用程序中成功运行。

以前有人遇到过这个问题吗?有解决办法吗?

提前致谢

---发出的命令序列如下:

     (env) D:\git\rebootv2.1\blog>python manage.py migrate
     D:\Python27\Lib\site-packages\treebeard\mp_tree.py:102: RemovedInDjango18Warning:      `MP_NodeManager.get_query_set` method
 should be renamed `get_queryset`.
   class MP_NodeManager(models.Manager):

 Operations to perform:
   Synchronize unmigrated apps: account, allauth, modelcluster, blog, compressor, facebook,      wagtailsnippets, socialaccount
   Apply all migrations: core, wagtailusers, wagtailembeds, wagtailadmin, sessions, admin,      wagtailcore, sites, auth, contenttypes, wagtaildocs, taggit, wagtailsearch, wagtailforms,      wagtailredirects, wagtailimages
 Synchronizing apps without migrations:
   Creating tables...
   Installing custom SQL...
   Installing indexes...
 Running migrations:
   Applying sites.0001_initial...Traceback (most recent call last):
   File "manage.py", line 10, in <module>
     execute_from_command_line(sys.argv)
   File "D:\Python27\Lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
utility.execute()
   File "D:\Python27\Lib\site-packages\django\core\management\__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
   File "D:\Python27\Lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
   File "D:\Python27\Lib\site-packages\django\core\management\base.py", line 338, in execute
output = self.handle(*args, **options)
   File "D:\Python27\Lib\site-packages\django\core\management\commands\migrate.py", line 160, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
   File "D:\Python27\Lib\site-packages\django\db\migrations\executor.py", line 63, in migrate
self.apply_migration(migration, fake=fake)
   File "D:\Python27\Lib\site-packages\django\db\migrations\executor.py", line 91, in apply_migration
if self.detect_soft_applied(migration):
   File "D:\Python27\Lib\site-packages\django\db\migrations\executor.py", line 135, in detect_soft_applied
apps = project_state.render()
   File "D:\Python27\Lib\site-packages\django\db\migrations\state.py", line 71, in render raise InvalidBasesError("Cannot resolve bases for %r\nThis can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)\n in an app with no migrations; see https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more" % new_unrendered_models)
 django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<ModelState: 'blog.BlogPage'>, <ModelState: 'blog.BlogIndexPage'>]
 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

 (env) D:\git\rebootv2.1\blog>python manage.py makemigrations
 D:\Python27\Lib\site-packages\treebeard\mp_tree.py:102: RemovedInDjango18Warning: `MP_NodeManager.get_query_set` method
 should be renamed `get_queryset`.
   class MP_NodeManager(models.Manager):

 No changes detected

[为我解决了这个问题] - 我猜最终是排序问题....

  1. 在 settings.py 中禁用 INSTALLED_APPS 中的所有 allauth 应用
  2. 运行 manage.py migrate 启用所有 allauth 应用程序并禁用 为项目生成的 wagtail 应用(例如博客)
  3. 再次运行 manage.py migrate 在 INSTALLED_APPS 中启用两组应用
  4. 再次运行 manage.py migrate

现在似乎很开心。

希望这可以帮助某人并节省他们一些时间!

【问题讨论】:

  • “博客”应用是否创建了任何迁移?
  • 是的。现在好像修好了。 manage.py 迁移顺利进行。我解决这个问题的方法是:在 settings.py 中禁用 INSTALLED_APPS 中的所有 allauth 应用程序运行 manage.py 迁移启用所有 allauth 应用程序并禁用为项目(例如博客)生成的 wagtail 应用程序运行 manage.py再次迁移在 INSTALLED_APPS 中启用两组应用程序运行 manage.py 再次迁移似乎现在很开心。希望这可以帮助某人并节省他们一些时间!
  • 您也可以在Answer 中提供此详细信息....!
  • 现在更新了答案

标签: django django-allauth django-1.7 wagtail


【解决方案1】:

我猜是排序问题....

  1. 在 settings.py 中禁用 INSTALLED_APPS 中的所有 allauth 应用
  2. 运行 manage.py migrate 启用所有 allauth 应用并禁用为项目(例如博客)生成的 wagtail 应用
  3. 再次运行 manage.py migrate 在 INSTALLED_APPS 中启用两组应用
  4. 再次运行 manage.py migrate

现在似乎很开心。

希望这可以帮助某人并节省他们一些时间!

【讨论】:

  • 我做的有点像你,评论了我的大部分应用程序,运行./manage.py migrate,它faked迁移,我取消注释我自己的应用程序,运行./manage.py makemigrations,这一次,它检测到变化和更新了我的迁移。我随机取消了一些 INSTALLED_APPS 的注释并设法运行了所有迁移。我认为这发生在我身上是因为我更新了 django 和 django-cms,也许我跳过了一些迁移,无论如何,谢谢你的提示,现在可以正常工作了 :)
  • 似乎工作了一段时间,但我尝试添加其他应用程序并再次遇到同样的问题。 bitbucket.org/bercab/cmsplugin-nivoslider/issue/10/…
  • 我终于知道发生了什么,cmsfiler 使用自定义模块名称进行 django 的迁移(migrations_django 而不是 migrations)。详情在这里:bitbucket.org/bercab/cmsplugin-nivoslider/issue/10/…参考:docs.djangoproject.com/en/1.7/ref/settings/…
  • 我还需要停止从urls.py 到我的应用程序的链接。
【解决方案2】:

我在尝试让 wagtail demo 工作时遇到了这个问题(没有尝试安装第 3 方应用程序)。因为错误出现在 treebeard 中,所以我猜测可能有更新的版本可用。果然,这成功了:

pip uninstall django-treebeard
pip install django-treebeard==3.0

现在我可以在 wagtail 演示设置中运行此命令而不会出错:

./manage.py load_initial_data

【讨论】:

  • 我今天尝试了这种方法,但它似乎对我不起作用。很高兴听到它对你有用。
【解决方案3】:

我也遇到了错误Cannot resolve bases for ... This can happen if you are inheriting models from an app with migrations。这是因为python manage.py makemigrations 没有创建任何迁移文件。这是因为我没有 migrations 文件夹。在我添加了那个文件夹(和一个空的__init__.py 里面)之后一切都很好。

【讨论】:

  • 刚刚也将此修复用于 1.710
  • 这就是我遇到相同类型错误的解决方案
【解决方案4】:

在我的例子中,我创建了继承自 auth.models.User 的模型

class User(auth.models.User, auth.models.PermissionsMixin):
    def __str__(self):
        return "@{}".format(self.username)

这就是错误的原因。

解决方案:

禁用(cmets)该模型 => 运行迁移 => 启用该模型 => 再次运行迁移。它应该可以工作。

【讨论】:

    【解决方案5】:

    就我而言,这是因为我在设置“.gitignore”期间删除了特定应用程序文件夹下的“迁移”文件夹。 Wagtail 需要这些表,但它无法创建。所以在这种情况下,需要:

    1. 确保在每个创建的应用文件夹(带有 models.py)和 __init__.py 文件中都有“迁移”文件夹。 如果没有,请在必要时创建两者。
    2. 运行python manage.py makemigrations 它将检查迁移文件夹是否有正确的说明来创建所有必要的实际表,如果不存在则创建 0001_initial.py。
    3. 运行python manage.py migrate

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-03
      • 2015-01-07
      • 2016-02-14
      • 2012-08-06
      • 2015-02-09
      • 1970-01-01
      • 2018-01-14
      • 2018-01-04
      相关资源
      最近更新 更多