Confused with deleted migrations

30 views
Skip to first unread message

Mohammad Etemaddar

unread,
Jun 12, 2019, 2:27:56 PM6/12/19
to Django users
Hey folks
After uploading the app to the server, I got problems by local migrations in development. So deleted the migrations and local sqlite db (Server uses MySQL).
After more development, uploaded the whole project to the server and overwrite the files. And typed migrate on server. I don't know what happened to the database. Some new tables seems to be created (or not). I got really confused with this situation. It is much confusing to get backup from server's data and then restore them back.
What is your opinion?

Andréas Kühne

unread,
Jun 13, 2019, 4:23:04 AM6/13/19
to django...@googlegroups.com
Hi Mohammed,

You need to make sure that all migrations that you do in development also can be run on the production machine - the migrations should be version controlled and checked in. Then you can run migrate when deploying new code and all migrations should just work. This is how I do it at least.

It seems as though you have different migrations on the server and development machine? I think that adds complexity that you really don't want.

And it doesn't matter if you have mysql on the production server and sqlite locally. The database settings should differ but the migrations are (more or less) database agnostic, so you should be able to run the same migrations (as long as you don't use specific database fields).

Regards,

Andréas


--
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...@googlegroups.com.
To post to this group, send email to django...@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/d050785c-3924-40cb-8c9c-2b878dda4ad5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mohammad Etemaddar

unread,
Jun 16, 2019, 3:05:03 AM6/16/19
to Django users
I got really confused. I don't know how to use version control. I think this might happen again.
I need to understand what you did with version control. It would be appreciated if you could post an instructions on here or any blog.
Thank you.

Andréas Kühne

unread,
Jun 17, 2019, 5:20:00 AM6/17/19
to django...@googlegroups.com
Hi,

If you look here:

You will see Djangos official take on migrations - you don't need to use version control for handling them (see here for examples of version control: https://en.wikipedia.org/wiki/Version_control). 

The main thing however is that you need to make sure that the migration files (in each apps migrations directory) should always be added to, and you should never delete files there. So if you are working on a project and developing it locally - you do the changes on the models and then run "python manage.py makemigrations". Django will then create migration files for you that have the changes you just have done. These you need to keep all the time (you can also squash migrations, but that's rather advanced). These migration files can be run both on you development server and on your production server - they will do the changes required.

It SHOULDN'T matter which database you use on production and development, however - I usually use the same locally and on production, just to make sure that we don't get any strange issues because of differences. But that's just me :-)

Regards,

Andréas


--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages