Django provides the comfort database migrations from its version 1.8, with which we can avoid the usage of third party packages like the south. Adding migrations to new apps is straightforward - they come preconfigured to accept migrations, and so just run make migrations once you’ve made some changes. But if your app already has models and database tables, and doesn’t have migrations yet (for example, you created it against a previous Django version) or you got your migrations messed up, you’ll need to convert your app to use migrations. Following are the steps to create initial migrations to your app:
Step1: Empty the django_migrations table:
Just go to your corresponding database terminals and delete all the records from you django_migrations table with
delete from django_migrations;
Step2: Remove all the files in migrations folders in each and every app of your project.
Go to terminal and run remove all files in migrations folder with
rm -rf <app>/migrations/
Step3: Reset the migrations for the "built-in" apps:
Reset all the migrations of the Django's built-in apps like admin with the command
python manage.py migrate --fake
Step4: Create initial migrations for each and every app:
For each app run:
python manage.py makemigrations <app>.
Step5: Final step is to create fake initial migrations:
To create initial fake migrations just run
python manage.py migrate --fake-initial
With all the above five steps all the initial migrations will be created for the existing database schema. Now you can use the Django's migrations system normally. To test if the migrations are succeeded or not, just add a new field to any of the models and run python manage.py make migrations and then it will create a migration file in the corresponding migrations folder of the corresponding app, and then run python manage.py migrate. If this succeeds our above steps are the success and you can enjoy the beauty of Django's migrations.
Reduce database queries in django with Conditional Expressions. By using Conditional Expressions we can use "If...Elif...Else" expressions while querying the database so that we can ...
Now we are going to index text content which is stored in structured files such as PDFs, Microsoft Office documents, images, etc using haystack and ...
Django comes with a simple permissions system. It provides a way to assign permissions to specific users and groups of users. We can have permissions ...
MicroPyramid - India
HIG499, 6th phase KPHB, Hyderabad, India - 500072, +91 9959166266
Monday - Friday : 10:00 - 19:00
MicroPyramid - USA
280 Moon Clinton Rd,STE D Moon Twp, Pittsburgh, Pennsylvania 15108, +1 5102300949
MicroPyramid - UAE
Khalifa Building(Near Old Nesto Super Market),Opp Fire Station, Sharjah, UAE 341246, +971 566061239