[Django] #25216: DB migration bug in 1.8.3 when creating ManyToMany relation.

10 views
Skip to first unread message

Django

unread,
Aug 3, 2015, 7:29:28 PM8/3/15
to django-...@googlegroups.com
#25216: DB migration bug in 1.8.3 when creating ManyToMany relation.
----------------------------+---------------------
Reporter: cx44yale | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Keywords: migrate
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+---------------------
Hi,
I have the following very simple code:

from django.contrib.auth.models import User

class Agent(models.Model):

name = models.CharField(max_length=100)
users = models.ManyToManyField(User, related_name='accessible_agents',
default=[])

and when I have an empty database, and do python manage.py migrate.

It gives me error, and I tested on 1.7.8, it works fine.

Operations to perform:
Synchronize unmigrated apps: staticfiles, download, messages
Apply all migrations: admin, auth, contenttypes, sessions
Synchronizing apps without migrations:
Creating tables...
Creating table download_agent
Running deferred SQL...
Traceback (most recent call last):
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/django/db/backends/mysql/base.py", line 124, in execute
return self.cursor.execute(query, args)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/MySQLdb/cursors.py", line 220, in execute
self.errorhandler(self, exc, value)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorvalue
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/MySQLdb/cursors.py", line 209, in execute
r = self._query(query)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/MySQLdb/cursors.py", line 371, in _query
rowcount = self._do_query(q)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/MySQLdb/cursors.py", line 335, in _do_query
db.query(q)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/MySQLdb/connections.py", line 280, in query
_mysql.connection.query(self, query)
_mysql_exceptions.OperationalError: (1005, "Can't create table
'portal_aperture.#sql-403_b3' (errno: 150)")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/django/core/management/__init__.py", line 338, in
execute_from_command_line
utility.execute()
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/django/core/management/commands/migrate.py", line 179, in handle
created_models = self.sync_apps(connection,
executor.loader.unmigrated_apps)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/django/core/management/commands/migrate.py", line 317, in
sync_apps
cursor.execute(statement)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/django/utils/six.py", line 658, in reraise
raise value.with_traceback(tb)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/django/db/backends/mysql/base.py", line 124, in execute
return self.cursor.execute(query, args)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/MySQLdb/cursors.py", line 220, in execute
self.errorhandler(self, exc, value)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorvalue
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/MySQLdb/cursors.py", line 209, in execute
r = self._query(query)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/MySQLdb/cursors.py", line 371, in _query
rowcount = self._do_query(q)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/MySQLdb/cursors.py", line 335, in _do_query
db.query(q)
File "/srv/company/virtualenvs/portal_aperture/lib/python3.4/site-
packages/MySQLdb/connections.py", line 280, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (1005, "Can't create table
'portal_aperture.#sql-403_b3' (errno: 150)")

Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/25216>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 3, 2015, 7:31:00 PM8/3/15
to django-...@googlegroups.com
#25216: DB migration bug in 1.8.3 when creating ManyToMany relation.
----------------------------+--------------------------------------

Reporter: cx44yale | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:

Keywords: migrate | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by cx44yale):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/25216#comment:1>

Django

unread,
Aug 3, 2015, 7:37:38 PM8/3/15
to django-...@googlegroups.com
#25216: DB migration bug in 1.8.3 when creating ManyToMany relation.
----------------------------+--------------------------------------

Reporter: cx44yale | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:

Keywords: migrate | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Description changed by cx44yale:

Old description:

New description:

Hi,
I am using python version 3.4 and django 1.8.3, I have the following very
simple code:

from django.contrib.auth.models import User

class Agent(models.Model):

Thanks.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25216#comment:2>

Django

unread,
Aug 3, 2015, 7:55:34 PM8/3/15
to django-...@googlegroups.com
#25216: DB migration bug in 1.8.3 when creating ManyToMany relation.
----------------------------+--------------------------------------

Reporter: cx44yale | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:

Keywords: migrate | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------

Comment (by cx44yale):

I suspect it is a problem with the order executed, the M2M expects my User
model.

I removed all of my models definition in that app, and run python
manage.py migrate to generate all those auth, sessions builtin tables, and
then paste my models back run migrate again, this time everything works,
and all the tables are generated correctly.

Thanks

--
Ticket URL: <https://code.djangoproject.com/ticket/25216#comment:3>

Django

unread,
Aug 3, 2015, 8:11:44 PM8/3/15
to django-...@googlegroups.com
#25216: DB migration bug in 1.8.3 when creating ManyToMany relation.
----------------------------+--------------------------------------

Reporter: cx44yale | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:

Keywords: migrate | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Description changed by timgraham:

Old description:

> Hi,
> I am using python version 3.4 and django 1.8.3, I have the following very

New description:

Hi,
I am using python version 3.4 and django 1.8.3, I have the following very

class Agent(models.Model):

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25216#comment:4>

Django

unread,
Aug 3, 2015, 8:25:22 PM8/3/15
to django-...@googlegroups.com
#25216: DB migration bug in 1.8.3 when creating ManyToMany relation.
----------------------------+--------------------------------------

Reporter: cx44yale | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:

Keywords: migrate | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Description changed by cx44yale:

Old description:

> Hi,
> I am using python version 3.4 and django 1.8.3, I have the following very

New description:

Hi,
I am using python version 3.4 and django 1.8.3, I have the following very


simple code:
{{{
from django.contrib.auth.models import User

class Agent(models.Model):

name = models.CharField(max_length=100, primary_key=True)

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25216#comment:5>

Django

unread,
Aug 4, 2015, 7:04:46 AM8/4/15
to django-...@googlegroups.com
#25216: DB migration bug in 1.8.3 when creating ManyToMany relation.
----------------------------+--------------------------------------

Reporter: cx44yale | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:

Keywords: migrate | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------

Comment (by timgraham):

Did you create migrations for your app using `makemigrations`? If not, you
have an unmigrated app depending on a migrated one as described
[https://docs.djangoproject.com/en/1.8/topics/migrations/#dependencies in
the docs] which is an invalid configuration.

--
Ticket URL: <https://code.djangoproject.com/ticket/25216#comment:6>

Django

unread,
Aug 6, 2015, 12:15:36 PM8/6/15
to django-...@googlegroups.com
#25216: DB migration bug in 1.8.3 when creating ManyToMany relation.
----------------------------+--------------------------------------
Reporter: cx44yale | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Normal | Resolution: needsinfo

Keywords: migrate | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => needsinfo


Comment:

Please reopen with a sample project to reproduce the problem if my last
comment is incorrect. Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/25216#comment:7>

Reply all
Reply to author
Forward
0 new messages