Migrating existing auth.User data to new Django 1.5 custom user model?

South is more than able to do this migration for you, but you need to be smart and do it in stages. Here’s the step-by-step guide: (This guide presupposed you subclass AbstractUser, not AbstractBaseUser) Before making the switch, make sure that south support is enabled in the application that contains your custom user model (for … Read more

Easiest way to rename a model using Django/South?

To answer your first question, the simple model/table rename is pretty straightforward. Run the command: ./manage.py schemamigration yourapp rename_foo_to_bar –empty (Update 2: try –auto instead of –empty to avoid the warning below. Thanks to @KFB for the tip.) If you’re using an older version of south, you’ll need startmigration instead of schemamigration. Then manually edit … Read more

Django – How to rename a model field using South?

You can use the db.rename_column function. class Migration: def forwards(self, orm): # Rename ‘name’ field to ‘full_name’ db.rename_column(‘app_foo’, ‘name’, ‘full_name’) def backwards(self, orm): # Rename ‘full_name’ field to ‘name’ db.rename_column(‘app_foo’, ‘full_name’, ‘name’) The first argument of db.rename_column is the table name, so it’s important to remember how Django creates table names: Django automatically derives the … Read more

django 1.7 migrate gets error “table already exists”

If you have the table created in the database, you can run python manage.py migrate –fake <appname> Mark migrations as run without actually running them Or if you want to avoid some actions in your migration, you can edit the migration file under the app/migrations directory and comment the operations you don’t want to do … Read more

How do I migrate a model out of one django app and into a new one?

How to migrate using south. Lets say we got two apps: common and specific: myproject/ |– common | |– migrations | | |– 0001_initial.py | | `– 0002_create_cat.py | `– models.py `– specific |– migrations | |– 0001_initial.py | `– 0002_create_dog.py `– models.py Now we want to move model common.models.cat to specific app (precisely to … Read more

What is the best approach to change primary keys in an existing Django app?

Agreed, your model is probably wrong. The formal primary key should always be a surrogate key. Never anything else. [Strong words. Been database designer since the 1980’s. Important lessoned learned is this: everything is changeable, even when the users swear on their mothers’ graves that the value cannot be changed is is truly a natural … Read more

What’s the recommended approach to resetting migration history using Django South?

If you need to selectively (for just one app) reset migrations that are taking too long, this worked for me. rm <app-dir>/migrations/* python manage.py schemamigration <app-name> –initial python manage.py migrate <app-name> 0001 –fake –delete-ghost-migrations Don’t forget to manually restore any dependencies on other apps by adding lines like depends_on = ((“<other_app_name>”, “0001_initial”),(“<yet_another_app_name>”, “0001_initial”)) to your … Read more

tech