Django: What are the best practices to migrate a project from sqlite to PostgreSQL

In my experience, dumping & restoring from SQL doesn’t work properly. You should follow this sequence instead: 1. Dump db contents to json $ ./manage.py dumpdata > dump.json 2. Switch the backend in settings.py DATABASES = { # COMMENT OUT: # ‘default’: dj_database_url.config(default=”sqlite:////full/path/to/your/database/file.sqlite”), # ADD THIS INSTEAD: ‘default’: dj_database_url.config(default=”postgres://localhost:5432/postgres_db_name”), } 3. Syncdb and migrate the … Read more

How do I move a column (with contents) to another table in a Rails migration?

I ended up using this migration (tested, it works, and rolls back successfully): class AddPropertyToUser < ActiveRecord::Migration def self.up add_column :users, :someprop, :string execute “UPDATE users u, profiles p SET u.someprop = p.someprop WHERE u.id = p.user_id” remove_column :profiles, :someprop end def self.down add_column :profiles, :someprop, :string execute “UPDATE profiles p, users u SET p.someprop … Read more

Implementation of “Automatic Lightweight Migration” for Core Data (iPhone)

This is what I did to make Automatic Lightweight Migration (Source: http://brainwashinc.wordpress.com/2010/01/18/iphone-coredata-automatic-light-migration/) 1. Set the Persistent Store options for automatic migration in the app delegate. Change your persistentStoreCoordinator creation to this (replace YOURDB): – (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator != nil) { return persistentStoreCoordinator; } NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @”YOURDB.sqlite”]]; // … Read more

How to implement IDbContextFactory for use with Entity Framework data migrations

I also hit this problem as i wrote my context to take a connection string name (and then used ninject to provide it). The process you’ve gone through seems correct, here is a snippet of my class implementation if it’s of any help: public class MigrationsContextFactory : IDbContextFactory<MyContext> { public MyContext Create() { return new … Read more

Is it worth using sqlalchemy-migrate ? [closed]

Use Alembic instead: http://pypi.python.org/pypi/alembic Thanks for comments, edited to add some reasoning — It’s developed by the author of SQLAlchemy, and it’s brand new and well supported. I don’t know enough about sqlalchemy-migrate to give a good comparison. But I took a quick read through the clear and concise Alembic docs, then got my own … 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

How to efficiently manage frequent schema changes using sqlalchemy?

Alembic is a new database migrations tool, written by the author of SQLAlchemy. I’ve found it much easier to use than sqlalchemy-migrate. It also works seamlessly with Flask-SQLAlchemy. Auto generate the schema migration script from your SQLAlchemy models: alembic revision –autogenerate -m “description of changes” Then apply the new schema changes to your database: alembic … Read more