Closed bijenkins closed 8 years ago
Failing Migration:
(ENV)[bijenkins@bmositedev siteAppsite]$ more /home/DOMAIN/bijenkins/.pyenv/versions/Graba/lib/python2.7/site-packages/dbmail/migrations/0006_auto_20150708_0714.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('dbmail', '0005_auto_20150506_2201'),
]
operations = [
migrations.CreateModel(
name='MailSubscription',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('backend', models.CharField(max_length=50, choices=[(b'dbmail.backends.mail', 'MailBox'), (b'dbmail.backends.push', 'Push'), (b'dbmail.backends.sms', 'SMS'), (b'dbmail.backends.t
ts', 'TTS')])),
('start_hour', models.CharField(default=b'00:00', max_length=5)),
('end_hour', models.CharField(default=b'23:59', max_length=5)),
('is_enabled', models.BooleanField(default=True, db_index=True)),
('is_checked', models.BooleanField(default=False, db_index=True)),
('defer_at_allowed_hours', models.BooleanField(default=False)),
('address', models.CharField(max_length=60)),
('user', models.ForeignKey(verbose_name='User', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
],
options={
'verbose_name': 'Mail Subscription',
},
),
]
I can not reproduce this problem. What I did:
git checkout d4b59d00144a84a90c5ad0fe2bbca9dce980de04
./manage.py syncdb
./manage.py migrate
git checkout master
./manage.py migrate
All is working fine without broken migrations. Env: Django 1.4.20, MySQL 5.6.26, Python 2.7.10
Test migration from PyPi (Django 1.4):
cd /tmp
mkvirtualenv dbmail-test
pip install Django==1.4.20 django-db-mailer==2.0.2 MySQL-python==1.2.5 South==1.0.2
django-admin.py startproject testing; cd testing/
cat >> ./testing/settings.py << END
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbmail_migration',
'USER': 'root',
'PASSWORD': '',
'HOST': '',
'PORT': '',
},
}
INSTALLED_APPS += (
'south',
'dbmail',
)
END
./manage.py syncdb --noinput
./manage.py migrate
pip install django-db-mailer==2.2.0
./manage.py migrate
and all is ok.
Test migration from PyPi (Django 1.8):
cd /tmp
mkvirtualenv dbmail-test
pip install Django==1.8.5 django-db-mailer==2.0.2 MySQL-python==1.2.5
django-admin.py startproject testing; cd testing/
cat >> ./testing/settings.py << END
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbmail_migration',
'USER': 'root',
'PASSWORD': '',
'HOST': '',
'PORT': '',
},
}
INSTALLED_APPS += (
'dbmail',
)
END
./manage.py migrate
pip install django-db-mailer==2.2.0
./manage.py migrate
... all is ok.
Give me a Django and MySQL version. And show me how I can reproduce this problem.
Django 1.7.4 Mysql 5.5
Can u run my examples?
I can't, south doesn't work on 1.7. I've discovered that even if I remove all traces of this library, and drop tables it still happens.
I can get the error to change slightly. First it will output this:
(site)[bijenkins@bmositedev siteAppsite]$ python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: allauth, app, tinymce, django_rq, suit
Apply all migrations: account, explorer, thunderdomeV2, sessions, admin, documentation, sites, auth, thunderdome, contenttypes, dbmail, servicepathtable, socialaccount
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
Applying dbmail.0006_auto_20150708_0714...Traceback (most recent call last):
File "manage.py", line 17, in <module>
execute_from_command_line(sys.argv)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 161, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/migrations/executor.py", line 68, in migrate
self.apply_migration(migration, fake=fake)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/migrations/executor.py", line 102, in apply_migration
migration.apply(project_state, schema_editor)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/backends/schema.py", line 82, in __exit__
self.execute(sql)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/backends/schema.py", line 102, in execute
cursor.execute(sql, params)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 129, in execute
return self.cursor.execute(query, args)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.OperationalError: (1005, "Can't create table 'siteV2.#sql-2187_2775' (errno: 150)")
And thend if I run Migrate again it goes to this output:
(site)[bijenkins@bmositedev siteAppsite]$ python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: allauth, app, tinymce, django_rq, suit
Apply all migrations: account, explorer, thunderdomeV2, sessions, admin, documentation, sites, auth, thunderdome, contenttypes, dbmail, servicepathtable, socialaccount
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
Applying dbmail.0006_auto_20150708_0714...Traceback (most recent call last):
File "manage.py", line 17, in <module>
execute_from_command_line(sys.argv)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 161, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/migrations/executor.py", line 68, in migrate
self.apply_migration(migration, fake=fake)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/migrations/executor.py", line 102, in apply_migration
migration.apply(project_state, schema_editor)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/migrations/migration.py", line 108, in apply
operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/migrations/operations/models.py", line 36, in database_forwards
schema_editor.create_model(model)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/backends/schema.py", line 261, in create_model
self.execute(sql, params)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/backends/schema.py", line 102, in execute
cursor.execute(sql, params)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 129, in execute
return self.cursor.execute(query, args)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/home/DOMAIN/bijenkins/.pyenv/versions/site/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.OperationalError: (1050, "Table 'dbmail_mailsubscription' already exists")
If I drop only that table, it reverts to the same first error. It seems that because this migration fails
python2.7/site-packages/dbmail/migrations/0006_auto_20150708_0714.py:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('dbmail', '0005_auto_20150506_2201'),
]
operations = [
migrations.CreateModel(
name='MailSubscription',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('backend', models.CharField(max_length=50, choices=[(b'dbmail.backends.mail', 'MailBox'), (b'dbmail.backends.push', 'Push'), (b'dbmail.backends.sms', 'SMS'), (b'dbmail.backends.t
ts', 'TTS')])),
('start_hour', models.CharField(default=b'00:00', max_length=5)),
('end_hour', models.CharField(default=b'23:59', max_length=5)),
('is_enabled', models.BooleanField(default=True, db_index=True)),
('is_checked', models.BooleanField(default=False, db_index=True)),
('defer_at_allowed_hours', models.BooleanField(default=False)),
('address', models.CharField(max_length=60)),
('user', models.ForeignKey(verbose_name='User', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
],
options={
'verbose_name': 'Mail Subscription',
},
),
]
Also now when I uninstalled this software and dropped all tables to start fresh, it only creates the the mailsubscription table when running migrations.
When I research the first error I see that it looks like it's possibly related to the engine being used?
http://stackoverflow.com/questions/1457305/mysql-creating-tables-with-foreign-keys-giving-errno-150
Use my examples above.
Test migration from PyPi (Django 1.7. Logs here https://gist.github.com/gotlium/87a2110bf1a7b43b7312):
cd /tmp
mkvirtualenv dbmail-test
pip install Django==1.7.10 django-db-mailer==2.0.2 MySQL-python==1.2.5
django-admin.py startproject testing; cd testing/
cat >> ./testing/settings.py << END
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbmail_migration',
'USER': 'root',
'PASSWORD': '',
'HOST': '',
'PORT': '',
},
}
INSTALLED_APPS += (
'dbmail',
)
END
mysql -uroot -e 'create database dbmail_migration;'
./manage.py migrate
pip install django-db-mailer==2.2.0
./manage.py migrate
... all is ok.
Check your DB engine. Maybe you are using InnoDB with MyISAM? or you have a problem with AUTH_USER_MODEL?
DEBUG (0.018) ALTER TABLE `dbmail_mailsubscription` ADD CONSTRAINT `dbmail_mailsubscription_user_id_440cd6feeb7e77b0_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`); args=[]
Also now when I uninstalled this software and dropped all tables to start fresh, it only creates the the mailsubscription table when running migrations.
you should cleanup migration table.
You are getting "Table 'dbmail_mailsubscription' already exists"
because you are trying to re-run migrate command.
This problem can not be reproduced at standard installation without sources, settings and environment. Sorry, but now I can not help to you, because all my tests is a successful.
Additional info about alter fk (http://stackoverflow.com/questions/16866318/adding-foreign-key-fails-in-mysql-errno-150)
Its almost always a case of type mismatch between the primary key and the foreign key. Some tips to help in most cases:
- Check to see if the table you area trying to relate uses an engine that supports foreing keys like InnoDB
- Check if the columns are identically typed and nulled. eg (the 2 columns MUST match type, type size and sign)
- Check if the destination column have an index or primary key.
Can you try mysql 5.6 to reproduce your problem?
Sure enough.
msql> ALTER TABLE `dbmail_mailsubscription` ADD CONSTRAINT `dbmail_mailsubscription_user_id_440cd6feeb7e77b0_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`);
ERROR 1005 (HY000): Can't create table 'GrabaV2.#sql-2187_27bf' (errno: 150)
mysql>
So I'm looking and I see:
which isn't compatible with:
My question here is what is advised, changing the dbmail table is more advisable as it doesn't have any data in it doesn't seem to be a issue on any other ones. I removed migrations and removed tables again, ran from fresh install on same db, with same error. So obviously these don't match up.
I went in and changed the collation and engine of auth_user to as db_mailsubscription. This must have occurred by accident by myself. This database orignally lived on a 5.1 Mysql instance, and was upgraded to 5.5, new tables were being created in InnoDB, and old were created in MyISAM. Thank you for the help.
(site)[bijenkins@bmograbadev siteAppsite]$ python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: allauth, app, tinymce, django_rq, suit
Apply all migrations: account, explorer, thunderdomeV2, sessions, admin, documentation, sites, auth, thunderdome, contenttypes, dbmail, servicepathtable, socialaccount
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
Applying dbmail.0001_initial... OK
Applying dbmail.0002_auto_20150321_1539... OK
Applying dbmail.0003_maillog_backend... OK
Applying dbmail.0004_auto_20150321_2214... OK
Applying dbmail.0005_auto_20150506_2201... OK
Applying dbmail.0006_auto_20150708_0714... OK
Applying dbmail.0007_auto_20150708_2016... OK
Applying dbmail.0002_auto_20151013_1509... OK
Applying dbmail.0008_merge... OK
Applying dbmail.0009_auto_20151022_1953... OK
(site)[bijenkins@bmograbadev siteAppsite]$
Getting the below error when upgrading from 2.02 to Current stable. Funny thing is, I've searched the table and there is NO dbmail_mailsubscription in the DB. So I don't know why this migration think's it's there.
RHEL 6.6 Python 2.7.10