Answer the question
In order to leave comments, you need to log in
How to fix South Python migrations error?
Adding a new field to the model
class Technics(models.Model):
tech_model = models.CharField(max_length=200)
tech_description = models.CharField(max_length=1500)
category_tech = models.ForeignKey(TechCategory)
pub_date = models.DateTimeField('date published')
brand = models.ForeignKey(Manufacturer)
currency = models.ForeignKey(Currency)
price = models.IntegerField(default=0)
created_by = models.IntegerField(default=0)
active = models.BooleanField()
pr_image = models.ImageField(upload_to="preview", null=True, blank=True) #new field
def __unicode__(self):
return "%s - %s - %s - %s - %s - %s - %s - %s" % (self.tech_model, self.pr_image, self.tech_description, self.pub_date >= timezone.now() - datetime.timedelta(days=1), self.brand, self.currency, self.price, self.created_by, self.active)
Running migrations for technics:
- Migrating forwards to 0008_auto__chg_field_technics_pr_image.
> technics:0006_auto__del_field_technics_pr_image
FATAL ERROR - The following SQL query failed: ALTER TABLE `technics_technics` DROP COLUMN `pr_image` CASCADE;
The error was: (1091, "Can't DROP 'pr_image'; check that column/key exists")
! Error found during real run of migration! Aborting.
! Since you have a database that does not support running
! schema-altering statements in transactions, we have had
! to leave it in an interim state between migrations.
! You *might* be able to recover with: = ALTER TABLE `technics_technics` ADD COLUMN `pr_image` varchar(100) NOT NULL DEFAULT '0'; []
- no dry run output for alter_column() due to dynamic DDL, sorry
! The South developers regret this has happened, and would
! like to gently persuade you to consider a slightly
! easier-to-deal-with DBMS (one that supports DDL transactions)
! NOTE: The error which caused the migration to fail is further up.
Error in migration: technics:0006_auto__del_field_technics_pr_image
Traceback (most recent call last):
File "/Users/elchinmirzayev/Documents/Aptana Studio 3 Workspace/dj_stroyka_165/manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/South-1.0-py2.7.egg/south/management/commands/migrate.py", line 111, in handle
ignore_ghosts = ignore_ghosts,
File "/Library/Python/2.7/site-packages/South-1.0-py2.7.egg/south/migration/__init__.py", line 220, in migrate_app
success = migrator.migrate_many(target, workplan, database)
File "/Library/Python/2.7/site-packages/South-1.0-py2.7.egg/south/migration/migrators.py", line 256, in migrate_many
result = migrator.__class__.migrate_many(migrator, target, migrations, database)
File "/Library/Python/2.7/site-packages/South-1.0-py2.7.egg/south/migration/migrators.py", line 331, in migrate_many
result = self.migrate(migration, database)
File "/Library/Python/2.7/site-packages/South-1.0-py2.7.egg/south/migration/migrators.py", line 133, in migrate
result = self.run(migration, database)
File "/Library/Python/2.7/site-packages/South-1.0-py2.7.egg/south/migration/migrators.py", line 114, in run
return self.run_migration(migration, database)
File "/Library/Python/2.7/site-packages/South-1.0-py2.7.egg/south/migration/migrators.py", line 84, in run_migration
migration_function()
File "/Library/Python/2.7/site-packages/South-1.0-py2.7.egg/south/migration/migrators.py", line 60, in <lambda>
return (lambda: direction(orm))
File "/Users/elchinmirzayev/Documents/Aptana Studio 3 Workspace/dj_stroyka_165/technics/migrations/0006_auto__del_field_technics_pr_image.py", line 12, in forwards
db.delete_column(u'technics_technics', 'pr_image')
File "/Library/Python/2.7/site-packages/South-1.0-py2.7.egg/south/db/mysql.py", line 28, in _column_rm
return func(self, table_name, column_name, *args, **opts)
File "/Library/Python/2.7/site-packages/South-1.0-py2.7.egg/south/db/mysql.py", line 227, in delete_column
super(DatabaseOperations, self).delete_column(table_name, name)
File "/Library/Python/2.7/site-packages/South-1.0-py2.7.egg/south/db/generic.py", line 54, in _column_rm
return func(self, table, column, *args, **opts)
File "/Library/Python/2.7/site-packages/South-1.0-py2.7.egg/south/db/generic.py", line 911, in delete_column
self.execute(self.delete_column_string % params, [])
File "/Library/Python/2.7/site-packages/South-1.0-py2.7.egg/south/db/generic.py", line 282, in execute
cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/util.py", line 69, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Library/Python/2.7/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
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 201, 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.OperationalError: (1091, "Can't DROP 'pr_image'; check that column/key exists")
Finished "/Users/elchinmirzayev/Documents/Aptana Studio 3 Workspace/dj_stroyka_165/manage.py migrate technics" execution.
Answer the question
In order to leave comments, you need to log in
judging by the name of the migration, you are deleting this field, not adding it - del_field_technics_pr_image
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question