Initial schema followed by migrations in MySQL #26

Open
peterbe opened this Issue Jul 5, 2011 · 3 comments

Projects

None yet

2 participants

@peterbe
Contributor
peterbe commented Jul 5, 2011

I'm stabbing in the dark here but I can't get a seemingly simple mysql set to work at all with nashvegas. It gets tangled in transaction juggling.

I have

migrations/000_initial_schema.sql
migrations/001_some_alter_table.sql

And this doesn't work. There are no BEGIN or COMMIT or anything like that in any of the .sql files. As output I get this:

Exception _mysql_exceptions.OperationalError: (2013, 'Lost connection to MySQL server during query') in <bound method Cursor.__del__ of <MySQLdb.cursors.Cursor object at 0x102554ad0>> ignored
Executing 0001_webby-stage-auth_bug653180.sql... 

So, I thought perhaps it's not right that the cursor is re-created in each iteration of the loop so I moved it outside and tried again. Now I get this:

Rolled back all migrations.
Traceback (most recent call last):
  File "./manage.py", line 41, in <module>
    execute_manager(settings)
  File "/private/tmp/elmos/1/elmo/vendor/src/django/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/private/tmp/elmos/1/elmo/vendor/src/django/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/private/tmp/elmos/1/elmo/vendor/src/django/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/private/tmp/elmos/1/elmo/vendor/src/django/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/private/tmp/elmos/1/elmo/vendor-local/lib/python/nashvegas/management/commands/upgradedb.py", line 309, in handle
    self.execute_migrations(show_traceback=True)
  File "/private/tmp/elmos/1/elmo/vendor/src/django/django/db/transaction.py", line 217, in inner
    res = func(*args, **kwargs)
  File "/private/tmp/elmos/1/elmo/vendor-local/lib/python/nashvegas/management/commands/upgradedb.py", line 184, in execute_migrations
    cursor.execute(to_execute)
  File "/private/tmp/elmos/1/elmo/vendor/src/django/django/db/backends/util.py", line 34, in execute
    return self.cursor.execute(sql, params)
  File "/private/tmp/elmos/1/elmo/vendor/src/django/django/db/backends/mysql/base.py", line 86, in execute
    return self.cursor.execute(query, args)
  File "/Users/peterbe/virtualenvs/elmo/lib/python2.6/site-packages/MySQLdb/cursors.py", line 154, in execute
    charset = db.character_set_name()
django.db.utils.DatabaseError: (2014, "Commands out of sync; you can't run this command now")
Exception _mysql_exceptions.OperationalError: (2013, 'Lost connection to MySQL server during query') in <bound method Cursor.__del__ of <MySQLdb.cursors.Cursor object at 0x102540ad0>> ignored

One last time, I removed all my debugging modifications from upgradedb.py and moved away all files (migrations/*.sql) except the one called 000_initial_schema.sql and then I get this error:

Executing 0000_initial_schema.sql... Rolled back all migrations.
Traceback (most recent call last):
  File "./manage.py", line 41, in <module>
    execute_manager(settings)
  File "/private/tmp/elmos/1/elmo/vendor/src/django/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/private/tmp/elmos/1/elmo/vendor/src/django/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/private/tmp/elmos/1/elmo/vendor/src/django/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/private/tmp/elmos/1/elmo/vendor/src/django/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/private/tmp/elmos/1/elmo/vendor-local/lib/python/nashvegas/management/commands/upgradedb.py", line 300, in handle
    self.execute_migrations(show_traceback=True)
  File "/private/tmp/elmos/1/elmo/vendor-local/lib/python/nashvegas/management/commands/upgradedb.py", line 192, in execute_migrations
    transaction.commit(using=self.db)
  File "/private/tmp/elmos/1/elmo/vendor/src/django/django/db/transaction.py", line 142, in commit
    connection.commit()
  File "/private/tmp/elmos/1/elmo/vendor/src/django/django/db/backends/__init__.py", line 201, in commit
    self._commit()
  File "/private/tmp/elmos/1/elmo/vendor/src/django/django/db/backends/__init__.py", line 46, in _commit
    return self.connection.commit()
_mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now")
Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") in <bound method Cursor.__del__ of <MySQLdb.cursors.Cursor object at 0x102554990>> ignored

I should add; my file (000_initial_schema.sql) is pretty big and it creates indexes and a bunch of other things.

@peterbe
Contributor
peterbe commented Jul 5, 2011

Here's how I have to solve this for now:

./manage.py syncdb --noinput
./manage.py upgradedb --seed 0003
emacs migrations/0004_new_stuff.sql
./manage.py upgradedb --execute
@paltman
Collaborator
paltman commented Jul 4, 2012

@peterbe I remember seeing the issue you describe on MySQL years ago when I worked with that database and it seemed to happen randomly separate and apart from running migrations, but I can't remember what the cause was. I realize this issue was reported over a year ago, but am trying to clean things up a bit and tend to things I have neglected on this project. Is this still an issue with later versions of nashvegas?

@peterbe
Contributor
peterbe commented Jul 5, 2012

Lemme compare how old our version is and see if an upgrade helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment