When I install a new package let's say
(myenv) $ pip install django-avatar
After having added it in my project
INSTALLED_APPS = (
#...
'avatar',
)
As I'm using South, I'll want to add the migration to my project
(myenv) $ python manage.py schemamigration avatar --initial
+ Added model avatar.Avatar
Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate avatar
Now git tells me that nothing have changed in my project
Where is this migration file ?
How can I deploy it ?
After you run that command, followed by ./manage.py migrate avatar the migration will be written to /migrations/0001_initial.py and to a table in your DB. For MySQL it's south_migrationhistory.
As for deployment, my preference is to run the south schemamigration and migrate commands on production. And to keep the local migrations directory off production.
I do this because I usually perform more migrations in development, and (until 1.7, anyway) that directory can get rather unwieldy.
Related
I have a Postgresql database connected with my django application, Now I have a existing table in the database and want to add a new field to this table using the migrate command. But when I try to add this new field to my models.py and run makemigration and migrate commands, django says there are no new migrations to apply. Can you help me with how to add a new field to existing table.
Try running makemigrations command specifying your app name like this:
python manage.py makemigrations myapp
and then try running migrate command
After a long research I got a solution as below:
pip install django-extensions
and add this in the install app of settings.py
INSTALLED_APPS = [
'django_extensions'
]
Now, run migrations for your installed apps
python manage.py makemigrations your_app_name
python manage.py migrtate your_app_name
Done! See Your Database...
I am using south in my django project. I just added social_auth in settings.py, when i run this command:
python manage.py schemamigration social_auth --auto
It says:Nothing seems to have changed.
Please let me know how can i create tables for social auth, as by this command the table is not getting created.
django-social-auth works perfectly except that it needs South and it doesn't work with newer versions of Django.
To remove the dependencies form South in django-social-auth, simply remove the migrations created by South and create new ones using the newer migration engine from Django 1.7 >.
This is how I fixed it:
# Install django (if you haven't) and django-social-auth
(my_venv)$ pip install django django-social-auth
# Delete the South migrations
# Using a virtual environment: my_venv
# In case you use python3, replace
(my_venv)$ rm <path_to_my_venv>/lib/python2.7/site-packages/social_auth/migrations/000*
# Create an dummy django project
(my_venv)$ django-admin startproject asdf
Add django-social-auth to the asdf/settings.py file
### asdf/asdf/settings.py
...
INSTALLED_APPS = (
...
'social_auth',
)
...
Finally create the new migration for django-social-auth
# Create new migrations
$ python asdf/manage.py makemigrations social_auth
# Delete the dummy django-project
$ rm -r asdf
This fix will work for all the Django projects that work under the same virtual environment.
I don't think you need to generate migrations for social_auth, since this app should already have its migrations. Rather, you need to execute them, so after you added 'social_auth' in your settings you have to run only this command:
python manage.py migrate social_auth
I have a Django proyect running in heroku for some time now, the thing is that, tree days ago, I've tryed to update my schema model but, every time I write
heroku run python manage.py migrate quizzer
heroku keeps telling me that everything's up to date, but I've changed my models.py folder and run schema migration as always.
If you know why this is happening or how can I force a schema migration to my heroku app please tell me how.
Ps: I cannot delete the hole database as the data stored in heroku and the data stored in my local server database are not the same, and I don't want to loose the data of my users
Here is a workflow for running a schemamigration on quizzer after modifying your models.py
./manage.py schemamigration quizzer --auto # create migration
./manage.py migrate quizzer # apply migration locally
git add .
git commit -m "Changed quizzer models, added schemamigration"
git push heroku
heroku run python manage.py migrate quizzer # apply migration on heroku
It sounds like you might have forgotten to check your migration file (usually found in appname/migrations) into git, commit it and push it to heroku.
I had this problem too. I solved this by running heroku restart and running the migrate command again. Don't know why it works (suspect it has to do with initial), but at least it works.
Hope that helps!
South might be missing from requirements.txt. Try:
pip freeze > requirements.txt
...followed by another git add/commit/push.
Also, according to the South installation instructions, syncdb must be run first, "to make the South migration-tracking tables". So try:
heroku run python manage.py syncdb
...then try the migrate command again.
I've been working with django + south for a while and still haven't nailed this issue down.
Take an existing project, with existing apps and existing migrations that have been added over time. Now suppose you want to deploy it to a new dev machine (for example) with a clean database.
What would be the process?
Remember the that settings at this point contains:
INSTALLED_APPS = (
'django.contrib.auth',
# ...
'south',
'myapp1',
'myapp2',
)
So on one hand, if you try to run the migrations, you won't get anything since no database exists yet. But if you try to syncdb it'll simply sync without the south migrations.
So what's the right process to do this?
How about syncdb, and then migrate?
$ python manage.py syncdb
$ python manage.py migrate
South's patched syncdb management command tells you as much at the end:
$ python manage.py syncdb
Syncing...
Creating tables ...
Installing custom SQL ...
Installing indexes ...
No fixtures found.
Synced:
> django.contrib.auth
Not synced (use migrations):
- myapp1
- myapp2
(use ./manage.py migrate to migrate these)
Adding South to an existing Django project. I have it installed on both the development machine and the "production" server.
I've done the following on the development machine, then: added South app to settings.py,
python manage.py syncdb
python manage.py convert_to_south myproject.myapp
then changed some models, then
python manage.py schemamigration myproject.myapp --auto
python manage.py migrate myproject.myapp
Seems to work so far. What I am now not so sure about is what to do on the production server. Just repeat all these steps manually? Upload modified settings.py, do syncdb, convert_to_south, upload modified models.py, do schemamigration, migrate? Something different? The tutorial here says something about adding migrations to the version control, so, presumably, they should be uploaded and somehow applied on the production server?
Furthermore, right now I am using sqlite3 on the development machine and mysql on the server - does it make things any different south-wise?
My guide says:
Install South on server. import south from shell just to make sure you are using the same python env.
Add 'south' to INSTALLED_APPS in settings.py.
Upload settings.py.
Restart server
python manage.py syncdb.
Upload new app/models.py and app/migrations/ dir.
Restart server.
python manage.py migrate app --fake 0001
python manage.py migrate app
To make sure the south migration table exists,
python manage.py syncdb
and then
python manage.py migrate myproject.myapp --fake 0001
python manage.py migrate myproject.myapp
That's what's worked for me. :)
No need to do this in Django >= 1.7
i am stuck on this more then 1 hour :)
and at last find 1.7 and more have in build upgrading-from-south
for more info https://docs.djangoproject.com/en/1.7/topics/migrations/#upgrading-from-south
may be this one help you