6
votes

I am having a trouble when applying a django south migration:

As always, I executed the migrate command after a successful schemamigration

python manage.py migrate webapp

The log console:

Running migrations for webapp:
 - Migrating forwards to 0020_auto__add_example.
 > webapp:0020_auto__add_example
TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK

The error is not related with the specific migration as if I move backwards and try another it shows the same message.

Edit. This is the log of the query:

(0.005) SELECT `south_migrationhistory`.`id`, `south_migrationhistory`.`app_name`, `south_migrationhistory`.`migration`, `south_migrationhistory`.`applied` FROM `south_migrationhistory` WHERE `south_migrationhistory`.`applied` IS NOT NULL ORDER BY `south_migrationhistory`.`applied` ASC; args=()
Running migrations for webapp:
 - Migrating forwards to 0020_auto__add_example.
 > webapp:0020_auto__add_example
(0.002) CREATE TABLE ROLLBACK_TEST (X INT); args=()
TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK
6
Can you enable sql logging and attach the results here? coderwall.com/p/uzhycatuxcanfly
@tuxcanfly, I have added it.Miquel
Thanks tuxcanfly. At least I learned how to log the database when executing django queries.Miquel

6 Answers

15
votes

I just ran into a similar issue.

  • MySQL 5.6.13 (on Amazon RDS)
  • Django==1.5.4
  • MySQL-python==1.2.4
  • South==0.8.2

I went through almost every possible fix here and through countless Google searches with zero luck.

I looked at the database schema and a table I had not created named 'ROLLBACK_TEST' was part of the schema.

Once I dropped that mystery table the migration ran flawlessly.

This table could only have originated via Django, South or possibly an internal process at Amazon as nothing else has access.

4
votes

I had the same problem with Django 1.6 and South 1.0 on a MySQL instance. After turning on the django.db.backends logger I realised the migration was stuck on the following SQL statement:

DEBUG (0.003) CREATE TABLE ROLLBACK_TEST (X INT); args=None

So I checked the database and sure enough found the ROLLBACK_TEST table. Deleting it resolved the problem:

$ manage.py dbshell
mysql> DROP TABLE ROLLBACK_TEST;
3
votes

I had the same problem and was banging my head for a while. It turns out my (MySQL) database user didn't have sufficient privileges. I assigned: ALTER, CREATE, DELETE, DROP, INDEX, INSERT, SELECT, UPDATE to the user and everything worked fine.

1
votes

I had the same problem and for me the solution was simply to give the proper rights of my sqlite development.db file to the user who was executing the python manage.py migrate webapp command. I had the file owned by www-data and hence couldn't work on the file.

0
votes

I am writing the answer to the problem I had as it can be useful for somebody.

After some time of debugging I found that the problem was not related with django. It was an issue with the database and the virtual machine that hosts it.

I restarted the database machine and the migrations are now working.

0
votes

When I came to the same issue my problem was more or less related to django. I explain.

I was working with different tabs in my console. One was used with a django shell to test my models and in another tab I run the migrations. I came to an integrity error in my shell tab. So, until I solved the problem (see this thread) or closed the tab, the error in migration tab persisted. As the former answer pointed out, this was something related to the DB -but not DB's fault.