#25140: Error when running test with MySQL database
-------------------------------------+-------------------------------------
Reporter: luccascorrea | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by zetab):
I maybe have same problem here.
{{{
Jesses-MacBook-Pro:cloudft asg$ python manage.py test main -v 3
Creating test database for alias 'default' ('test_db')...
Got an error creating the test database: (1007, "Can't create database
'test_db'; database exists")
Type 'yes' if you would like to try deleting the test database 'test_db',
or 'no' to cancel: yes
Destroying old test database 'default'...
Operations to perform:
Synchronize unmigrated apps: authtoken, corsheaders, staticfiles,
debug_toolbar, messages, raven.contrib.django, humanize, debug_panel
Apply all migrations: admin, contenttypes, main, auth, sessions
Synchronizing apps without migrations:
Running pre-migrate handlers for application main
Running pre-migrate handlers for application admin
Running pre-migrate handlers for application auth
Running pre-migrate handlers for application contenttypes
Running pre-migrate handlers for application sessions
Running pre-migrate handlers for application corsheaders
Running pre-migrate handlers for application debug_toolbar
Running pre-migrate handlers for application raven.contrib.django
Running pre-migrate handlers for application authtoken
Creating tables...
Creating table corsheaders_corsmodel
Creating table authtoken_token
Running deferred SQL...
Traceback (most recent call last):
File "manage.py", line 8, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-
packages/django/core/management/__init__.py", line 338, in
execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-
packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-
packages/django/core/management/commands/test.py", line 30, in
run_from_argv
super(Command, self).run_from_argv(argv)
File "/Library/Python/2.7/site-packages/django/core/management/base.py",
line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/Library/Python/2.7/site-
packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/Library/Python/2.7/site-packages/django/core/management/base.py",
line 441, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-
packages/django/core/management/commands/test.py", line 90, in handle
failures = test_runner.run_tests(test_labels)
File "/Library/Python/2.7/site-packages/django/test/runner.py", line
210, in run_tests
old_config = self.setup_databases()
File "/Library/Python/2.7/site-packages/django/test/runner.py", line
166, in setup_databases
**kwargs
File "/Library/Python/2.7/site-packages/django/test/runner.py", line
370, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE",
True),
File "/Library/Python/2.7/site-
packages/django/db/backends/base/creation.py", line 368, in create_test_db
test_flush=not keepdb,
File "/Library/Python/2.7/site-
packages/django/core/management/__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "/Library/Python/2.7/site-packages/django/core/management/base.py",
line 441, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-
packages/django/core/management/commands/migrate.py", line 179, in handle
created_models = self.sync_apps(connection,
executor.loader.unmigrated_apps)
File "/Library/Python/2.7/site-
packages/django/core/management/commands/migrate.py", line 317, in
sync_apps
cursor.execute(statement)
File "/Library/Python/2.7/site-packages/django/db/backends/utils.py",
line 64, in execute
return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 97, in
__exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Library/Python/2.7/site-packages/django/db/backends/utils.py",
line 62, in execute
return self.cursor.execute(sql)
File "/Library/Python/2.7/site-
packages/django/db/backends/mysql/base.py", line 124, in execute
return self.cursor.execute(query, args)
File "/Library/Python/2.7/site-packages/MySQLdb/cursors.py", line 205,
in execute
self.errorhandler(self, exc, value)
File "/Library/Python/2.7/site-packages/MySQLdb/connections.py", line
36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.IntegrityError: (1215, 'Cannot add foreign key
constraint')
}}}
If i open mysql server and write SHOW ENGINE INNODB STATUS\G,
it will print
{{{
LATEST FOREIGN KEY ERROR
------------------------
2015-08-31 17:36:23 12af59000 Error in foreign key constraint of table
test_db/#sql-7d4_a:
FOREIGN KEY (`user_id`) REFERENCES `main_userprofile` (`id`):
Cannot resolve table name close to:
(`id`)
}}}
makemigrations, migrate and runserver works fine. Tests is the only
problem here.
--
Ticket URL: <https://code.djangoproject.com/ticket/25140#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/070.43a9439f41d2abaa22ff14d025e6125e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.