Challenge: How to modify an existing model
Solution (Django < 1.7): This developer making a change manually would have to update the table with the exact Django expected syntax, and make perfect reflected changes to models.py. Or the developer could back up the data, wipe out the table, recreate it using syncdb, and reload the data.
Solution (Django >= 1.7): This developer updates the models.py file, run makemigrations, run migrate.
Not only does Django handle update the sql table perfectly, but a file is produced in the migrations folder that shows you the exact changes made in case you would like to change any. It is possible as well to use the command sqlmigrate to view the changes Django plans to make on your table.
Of course before hand the developer could have installed South, but the point here is the wonderful benefit of the now built in functionality. The migrate commands empower the developer to make changes to the project with little work and a lot of security.
Solution (Django < 1.7): This developer making a change manually would have to update the table with the exact Django expected syntax, and make perfect reflected changes to models.py. Or the developer could back up the data, wipe out the table, recreate it using syncdb, and reload the data.
Solution (Django >= 1.7): This developer updates the models.py file, run makemigrations, run migrate.
Not only does Django handle update the sql table perfectly, but a file is produced in the migrations folder that shows you the exact changes made in case you would like to change any. It is possible as well to use the command sqlmigrate to view the changes Django plans to make on your table.
Of course before hand the developer could have installed South, but the point here is the wonderful benefit of the now built in functionality. The migrate commands empower the developer to make changes to the project with little work and a lot of security.
No comments:
Post a Comment