question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error running shop.0007_notification_recipient migration using MySQL.

See original GitHub issue

Hi,

I am getting this error while trying to migrate an existing project to django-shop 0.11 - using MySQL. This only happens trying to migrate existing data, starting a fresh database works fine.

Applying shop.0007_notification_recipient...Traceback (most recent call last):
  File "manage.py", line 23, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/db/migrations/executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/db/migrations/migration.py", line 129, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 204, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 495, in alter_field
    old_db_params, new_db_params, strict)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 732, in _alter_field
    self.execute(self._create_fk_sql(model, new_field, "_fk_%(to_table)s_%(to_column)s"))
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 112, in execute
    cursor.execute(sql, params)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 110, in execute
    return self.cursor.execute(query, args)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "/Users/dino/.virtualenvs/ecuga.com/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
django.db.utils.IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (`ecuga_site`.`#sql-2a3_2e2`, CONSTRAINT `shop_notification_recipient_id_81184845_fk_auth_user_id` FOREIGN KEY (`recipient_id`) REFERENCES `auth_user` (`id`))')

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jriefcommented, Sep 12, 2017

Hugh, finally. Sorry for that and thanks for your patience.

I had to fix this model settings, because having an PositiveIntegerField holding either a pseudo foreign key, or a magic value, was a really bad idea. Therefore this change.

0reactions
dinoperoviccommented, Sep 12, 2017

Yes it works now! Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Diagnose issues for MySQL | Database Migration Service
Failure running migration job due to incompatible source and destination database versions. The source database version provided is incompatible with the ...
Read more >
MySQL Workbench Manual :: 10.5.1 Preparations
To migrate schemas and data from Microsoft SQL Server for use with MySQL, ensure the following: The source SQL Server instance is running,...
Read more >
10.2.1 A Visual Guide to Performing a Database Migration
From MySQL Workbench, choose Database and then Migrate to open the migration wizard and display the migration wizard overview (see the figure that...
Read more >
MySQL Workbench Manual :: 10 Database Migration Wizard
MySQL Workbench provides the ability to migrate ODBC-compliant databases to MySQL. Convert (migrate) different database types, including MySQL, across servers.
Read more >
MySQL Workbench Manual :: 10.4 Microsoft Access Migration
Microsoft Access stores relationship/foreign key information in an ... try to migrate without opening up access to it, then you will get an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found