Thursday, August 31, 2017

Re: A lot of Problems with Migrating (conceptual)

There are two main principles to remember about Django migrations in early development stage:

1) Make migrations often and coherent.
   Typically, if you change something about a model, make a migration.
   When you want to cover multiple models in one migration, there should be
   a good reason for it. If you can't think of it, don't.

2) When the design is flawed, don't add to the problem by creating another
   migration. Instead roll back, remove the migration file(s), alter the
   design and make a new migration.

The second principle is often overlooked and by applying the first, the
"damage" is minimized.

Rolling back is done by adding a migration number to the `migrate` management
command and it will roll back to the point including that migration.

Once you freeze the model design, feel free to squash some or all migrations
into one file if things got a little big.


On Wed, Aug 30, 2017 at 12:16 AM, Alexander Joseph <alexander.v.joseph@gmail.com> wrote:
Thanks James,
I'm actually starting over from scratch instead of actually refactoring so the accounts app is the only real app I have so far. I actually did delete the database and just apply migrations to the newly created database and it worked ok. I'd like to get better at fixing these migration problems though since I'll probably run into a lot of them and wont be able to delete the database once I have data.

Do you think it would have been better to run migrations for the specific accounts app? I thought it wouldnt matter much since accounts is my only app I have so far.

My new structure so far looks like this

business_management/
    business_management/
        accounts/
            migrations/
            __init__.py
            admin.py
            forms.py
            models.py
            tests.py
            views.py
        static/
        templates/
    config/
        settings/
            __init__.py
            base.py
            local.py
            production.py
        __init__.py
    docs/
        (developer documentation)
    requirements/
        (requirements.txt files)
    utility/
        (shell scripts)
    manage.py
    .gitignore




On Tuesday, August 29, 2017 at 3:35:21 PM UTC-6, James Schneider wrote:


On Tue, Aug 29, 2017 at 7:13 AM, Alexander Joseph <alexander...@gmail.com> wrote:
I'm not specifying the app level, I'm just running "python manage.py makemigrations --settings=config.settings.local"  and  "python manage.py migrate --settings=config.settings.local"
I'm not modifying the migrations files and I dont have an app with the label of admin, thats just the built-in admin. Thanks


I know you were doing a lot of refactoring. Did you rename the accounts app after performing an initial migration (applying an old migration with the old app name structure)? It sounds like your DB and your migration files might be out of sync. If you don't have any production data, I would recommend deleting and recreating the entire database, and deleting and recreating your migrations so that all the migrations are run in the correct order.

If you do have data you want to keep, then very likely you now have a ton of work to do writing custom migrations to sync everything back up manually. 

-James

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0686084f-1d5a-4f61-823e-7d84c58f317c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Melvyn Sopacua

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Bgw1GVEqNVRDvZuUn_3o02ZvL_vZJctBqbVNdfFCcmfMwPMuw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment