Skip to content

Instantly share code, notes, and snippets.

@erikcw
Last active August 29, 2015 14:05
Show Gist options
  • Save erikcw/307dc003cd2921a08eb2 to your computer and use it in GitHub Desktop.
Save erikcw/307dc003cd2921a08eb2 to your computer and use it in GitHub Desktop.
ForeignKey to IntegerField South Migration
# Initial state
class LogData(models.Model):
report_job = models.ForeignKey('myapp.ReportJobs')
#... more fields ...
# Step 1
# Change the field type and add the db_column parameter.
class LogData(models.Model):
report_job = models.IntegerField(db_column="report_job_id")
#... more fields ...
# run: ./manage schemamigration myapp --auto
# Step 2
# Rename the model field for backwords compatibility
class LogData(models.Model):
report_job_id = models.IntegerField(db_column="report_job_id")
#... more fields ...
# run: ./manage.py schemamigration myapp "rename_foreign_key_field" --empty
# NOTE --leave this migration empty, we are just using it to update South's record of frozen models to keep things consistent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment