Last active
August 29, 2015 14:05
-
-
Save erikcw/307dc003cd2921a08eb2 to your computer and use it in GitHub Desktop.
ForeignKey to IntegerField South Migration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Initial state | |
class LogData(models.Model): | |
report_job = models.ForeignKey('myapp.ReportJobs') | |
#... more fields ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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