Opened 11 years ago
Closed 11 years ago
#22051 closed Bug (fixed)
Running `makemigrations` twice in a row fails
Reported by: | Baptiste Mispelon | Owned by: | Andrew Godwin |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Release blocker | Keywords: | |
Cc: | numerodix@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
With the following (slightly contrived but still valid) models (taken from #22047):
from django.contrib.auth.models import User, Group from django.db import models class MyGroup(Group): users = models.ManyToManyField('bug22047.MyUser', through='Membership') class MyUser(User): pass class Membership(models.Model): user = models.ForeignKey(MyUser) group = models.ForeignKey(MyGroup)
Running manage.py makemigrations
for the first time works, but running it immediately after raises this error:
Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "./django/core/management/__init__.py", line 427, in execute_from_command_line utility.execute() File "./django/core/management/__init__.py", line 419, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "./django/core/management/base.py", line 287, in run_from_argv self.execute(*args, **options.__dict__) File "./django/core/management/base.py", line 336, in execute output = self.handle(*args, **options) File "./django/core/management/commands/makemigrations.py", line 99, in handle changes = autodetector.changes(graph=loader.graph, trim_to_apps=app_labels or None) File "./django/db/migrations/autodetector.py", line 33, in changes changes = self._detect_changes() File "./django/db/migrations/autodetector.py", line 50, in _detect_changes old_apps = self.from_state.render() File "./django/db/migrations/state.py", line 52, in render raise InvalidBasesError("Cannot resolve bases for %r" % new_unrendered_models) django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<django.db.migrations.state.ModelState object at 0x7f2353215e90>, <django.db.migrations.state.ModelState object at 0x7f23531b7350>]
Change History (14)
comment:1 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 11 years ago
Cc: | added |
---|
comment:3 by , 11 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:4 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:5 by , 11 years ago
Just tried running makemigrations twice and it still failed with the same error messages
follow-up: 7 comment:6 by , 11 years ago
I'll need more than that if I'm going to debug it - the models you used, the full error output, the Django commit hash you're working from.
comment:7 by , 11 years ago
Replying to andrewgodwin:
I'll need more than that if I'm going to debug it - the models you used, the full error output, the Django commit hash you're working from.
Does this help?
from django.db import models from django.contrib.auth.models import User from datetime import date import string import random class FunStuffUser(User): address = models.CharField(max_length=256, blank=True) dob = models.DateField(default=date(1900, 1, 1)) class Music(models.Model): name = models.CharField(max_length=256) key = models.CharField(max_length=10, primary_key=True)
Here is the model and this is the error message I receive
Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File ".\django-1.8.dev20140409113843-py3.3.egg\django\core\management\__init__.py", line 4 27, in execute_from_command_line utility.execute() File ".\django-1.8.dev20140409113843-py3.3.egg\django\core\management\__init__.py", line 4 19, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File ".\django-1.8.dev20140409113843-py3.3.egg\django\core\management\base.py", line 288, in run_from_argv self.execute(*args, **options.__dict__) File "C:\Python33\lib\site-packages\django-1.8.dev20140409113843-py3.3.egg\django\core\management\base.py", line 337, in execute output = self.handle(*args, **options) File ".\django-1.8.dev20140409113843-py3.3.egg\django\core\management\commands\makemigrati ons.py", line 99, in handle changes = autodetector.changes(graph=loader.graph, trim_to_apps=app_labels or None) File ".\django-1.8.dev20140409113843-py3.3.egg\django\db\migrations\autodetector.py", line 33, in changes changes = self._detect_changes() File ".\django-1.8.dev20140409113843-py3.3.egg\django\db\migrations\autodetector.py", line 50, in _detect_changes old_apps = self.from_state.render() File ".\django-1.8.dev20140409113843-py3.3.egg\django\db\migrations\state.py", line 52, in render raise InvalidBasesError("Cannot resolve bases for %r" % new_unrendered_models) django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<django.db.migrations.state.ModelState object at 0x0000000003A65940>]
comment:8 by , 11 years ago
Resolution: | fixed |
---|---|
Status: | closed → new |
comment:9 by , 11 years ago
I'm having this error now with the most recent 1.7 branch. (956bd644249337b9467c017aac4eec228dde8c5d) only with a different error:
(ph) ubuntu at placeholder in ~/newtest/bug_report (master●) $ ./manage.py makemigrations Traceback (most recent call last): File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/home/ubuntu/.venvs/ph/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 427, in execute_from_command_line utility.execute() File "/home/ubuntu/.venvs/ph/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 419, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/ubuntu/.venvs/ph/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **options.__dict__) File "/home/ubuntu/.venvs/ph/local/lib/python2.7/site-packages/django/core/management/base.py", line 337, in execute output = self.handle(*args, **options) File "/home/ubuntu/.venvs/ph/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 99, in handle changes = autodetector.changes(graph=loader.graph, trim_to_apps=app_labels or None) File "/home/ubuntu/.venvs/ph/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 33, in changes changes = self._detect_changes() File "/home/ubuntu/.venvs/ph/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 50, in _detect_changes old_apps = self.from_state.render() File "/home/ubuntu/.venvs/ph/local/lib/python2.7/site-packages/django/db/migrations/state.py", line 63, in render model=dangling_lookup[0])) ValueError: Lookup failed for model referenced by field report.Project.user: auth.User (ph) ubuntu at placeholder in ~/newtest/bug_report (master●) $ cat report/models.py from django.db import models from django.contrib.auth.models import User class StringField(models.CharField): def __init__(self, *args, **kwargs): kwargs['max_length'] = 255 return super(StringField, self).__init__(*args, **kwargs) class Project(models.Model): user = models.ForeignKey(User) name = StringField()
comment:11 by , 11 years ago
I'm running into the same thing as well. my initial makemigration
is fine, but if I try and run it again (even with no changes) I get the same
django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<django.db.migrations.state.ModelState object at 0x0000000003A65940>]
as everyone else.
comment:12 by , 11 years ago
If you are subclassing from User
maybe this will help:
In your model's migration file find string: bases=('auth.user',),
and replace it with bases=(User,),
. And don't forget to import: from django.contrib.auth.models import User
comment:14 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I think the bases error is a duplicate of #22447 as I cannot reproduce the error with the models in comment 7 and 9 on the latest master. Please open a new ticket if there are other issues.
Just tested this, it's no longer the case; previous fixes to state must have fixed it.