South migration for social auth - django

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

Related

Adding new field to existing database table in django python

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...

Django rest framework and south migrations inside my repo - how to set it up correctly?

I'm using Django==1.6.5 and djangorestframework==3.0.3 with South==0.8.4. And I am using virtualenv.
In settings INSTALLED_APPS I have both rest_framework.authtoken and rest_framework. Isn't the rest_framework.authtoken redundant?
When I run migrations it creates the migrations in my /Users/andi/.virtualenvs/my_virtualenv/lib/python2.7/site-packages/rest_framework/authtoken/migrations, which is of course not in my project's repo.
QUESTION:
How can I set up django rest framework to produce the migrations inside my project directory, so that, after running schemamigration locally, the only thing I have to run on server is migrate?
You are using django 1.6.5, in this version migrations were not introduced so its may give you error on running migrations because django rest framework auth token migration tries to import migrations from django.db
Upgrade your south package from 0.8.4 to 1.0.1 version that will solve your problem Please check the following link related to south version 1.0.1
http://south.readthedocs.org/en/latest/releasenotes/1.0.html

What's the proper way to run a south schemamigration in a Django package?

I'm working with a third-party Django package, and I'm not sure how to create a schemamigration. What's the equivalent of:
./manage.py schemamigration <app_name> when I don't have a ./manage.py?
While I don't think we can create South migrations without build a real django site(btw, you also need the django site for testing). Just treat your package like other django packages, and run schemamigration <your_app_name> to create migrations for it.
You only need to let django store migrations under your package's migrations directory instead of 'env/lib/pythonXX/site-packages/' You need to install your app with pip's editableā€ mode.
pip install -e local_path/to/your_package

South - Migrate PyPI package

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.

Setting up an existing Django + South project instance

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)