Migration error with Django 1.7.1
Asked Answered
G

5

7

I'm getting an error when performing a migration after introducing a new app (django-allauth). I'm not sure what else to try in order to fix the error. I've tried a few things but they don't seem to help unfortunately.

when running manage.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"),
 ]    

What I've tried so far:

  1. followed the advice here: https://stackoverflow.com/a/25858659 however this has not changed anything for me.
  2. I've also tried https://code.djangoproject.com/ticket/22051#comment:12 with no success.

note: makemigrations runs (no changes detected) but migrate fails.

platform setup: This is currently on Django 1.7.1 on a Windows box. django-allauth runs successfully within other apps on this box.

Has anyone come across this before and is there a fix?

thanks in advance

---issued command sequence below:

     (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

[what fixed this for me] - ended up being a problem with sequencing I guess....

  1. disable all of the allauth apps within INSTALLED_APPS in settings.py
  2. run manage.py migrate enable all of the allauth apps and disable the wagtail app that was generated for the project (e.g. blog)
  3. run manage.py migrate again enable both sets of apps in INSTALLED_APPS
  4. run manage.py migrate again

seems to be happy now.

hope this helps someone and saves them some time!

Gawlas answered 2/12, 2014 at 23:35 Comment(4)
Does the 'blog' app have any migrations created?Philbin
yes it did. Seems to now be fixed. manage.py migrate going through smoothly. What I did to fix this was: disable all of the allauth apps within INSTALLED_APPS in settings.py run manage.py migrate enable all of the allauth apps and disable the wagtail app that was generated for the project (e.g. blog) run manage.py migrate again enable both sets of apps in INSTALLED_APPS run manage.py migrate again seems to be happy now. hope this helps someone and saves them some time!Gawlas
You can provide this detail in Answer also .... !Cressler
now updated with the answerGawlas
G
13

ended up being a problem with sequencing I guess....

  1. disable all of the allauth apps within INSTALLED_APPS in settings.py
  2. run manage.py migrate enable all of the allauth apps and disable the wagtail app that was generated for the project (e.g. blog)
  3. run manage.py migrate again enable both sets of apps in INSTALLED_APPS
  4. run manage.py migrate again

seems to be happy now.

hope this helps someone and saves them some time!

Gawlas answered 17/12, 2014 at 12:28 Comment(4)
I did a bit like you, commented most of my apps, ran ./manage.py migrate, it faked migrations, I uncommented my own app, ran ./manage.py makemigrations, this time, it detected changes and updated my migrations. I randomly uncommented some INSTALLED_APPS and managed to run all of the migrations. I think This happened to me because I updated django and django-cms, Maybe I skipped some migrations, anyway, Thanks for that hint, works fine now :)Nightspot
Seemed to work for a while, but I tried adding other applications and having same problem again. bitbucket.org/bercab/cmsplugin-nivoslider/issue/10/…Nightspot
I finally found out what was going on, cms and filer use custom module name for django's migrations (migrations_django instead of migrations). Details here: bitbucket.org/bercab/cmsplugin-nivoslider/issue/10/… Reference: docs.djangoproject.com/en/1.7/ref/settings/…Nightspot
I also need to stop the link from urls.py to my apps.Cutter
E
19

I had the error Cannot resolve bases for ... This can happen if you are inheriting models from an app with migrations as well. It was caused because python manage.py makemigrations did not create any migration files. This was because I had no migrations folder. After I added that folder (and an empty __init__.py inside) all worked well.

Exosphere answered 22/1, 2016 at 17:51 Comment(2)
Just used this fix for 1.710 as wellDamselfly
That was the solution in my case for same type of errorDust
G
13

ended up being a problem with sequencing I guess....

  1. disable all of the allauth apps within INSTALLED_APPS in settings.py
  2. run manage.py migrate enable all of the allauth apps and disable the wagtail app that was generated for the project (e.g. blog)
  3. run manage.py migrate again enable both sets of apps in INSTALLED_APPS
  4. run manage.py migrate again

seems to be happy now.

hope this helps someone and saves them some time!

Gawlas answered 17/12, 2014 at 12:28 Comment(4)
I did a bit like you, commented most of my apps, ran ./manage.py migrate, it faked migrations, I uncommented my own app, ran ./manage.py makemigrations, this time, it detected changes and updated my migrations. I randomly uncommented some INSTALLED_APPS and managed to run all of the migrations. I think This happened to me because I updated django and django-cms, Maybe I skipped some migrations, anyway, Thanks for that hint, works fine now :)Nightspot
Seemed to work for a while, but I tried adding other applications and having same problem again. bitbucket.org/bercab/cmsplugin-nivoslider/issue/10/…Nightspot
I finally found out what was going on, cms and filer use custom module name for django's migrations (migrations_django instead of migrations). Details here: bitbucket.org/bercab/cmsplugin-nivoslider/issue/10/… Reference: docs.djangoproject.com/en/1.7/ref/settings/…Nightspot
I also need to stop the link from urls.py to my apps.Cutter
W
1

I encountered this while trying to get the wagtail demo working (without trying to install 3rd party apps). Because the error was in treebeard, I guessed that there might be a newer version available. Sure enough, this did the trick:

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

And now I can run this command in the wagtail demo setup without error:

./manage.py load_initial_data
Wootten answered 16/2, 2015 at 19:30 Comment(1)
i tried this method today but it didn't seem to work for me. Good to hear it worked for you.Gawlas
K
0

In my case, I created the model inheriting from auth.models.User

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

That is the cause of the error.

Solution:

Disable(comments) that model => run migrate => enable that model => run migrate again. It should work.

Krahmer answered 24/12, 2018 at 3:13 Comment(0)
F
0

In my case it was because I had deleted 'migrations' folder under specific app's folder during setting '.gitignore'. Wagtail needs these tables but it can't create. So in this case one needs to:

  1. make sure you have 'migrations' folder in each created app folder (with models.py) and __init__.py file inside. If not, create both where necessary.
  2. run python manage.py makemigrations It will check if migrations folder has correct instructions to create all necessary actual tables and create 0001_initial.py if it doesn't exist.
  3. run python manage.py migrate
Finished answered 17/8, 2021 at 13:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.