tangentlabs/django-oscar — pull request #823 by eukreign (2013-09-08 19:40:42+00:00)
Title: Fix for failing south migration on new oscar projects

This is a re-opening of previously closed pull request (because I did not provide error message originally). https://github.com/tangentlabs/django-oscar/pull/786

To illustrate the problem I have created a basic oscar project: https://github.com/eukreign/oscardepends

The only app this project overloads is the 'order' app. Below are the commands to create the initial schemamigration for order and then an attempt to syncdb --migrate.

This pull request fixes the error below and several other situations where the schema migration fails. I have three other projects that overload a different combination of oscar apps that all exhibited this problem, with this fix they all work fine.

```
(oscardepends)lex@ubuntu:~/projects/oscardepends$ ./manage.py schemamigration order --initial
Creating migrations directory at '/home/lex/projects/oscardepends/oscardepends/apps/order/migrations'...
Creating __init__.py in '/home/lex/projects/oscardepends/oscardepends/apps/order/migrations'...
+ Added model order.PaymentEventQuantity
+ Added model order.ShippingEventQuantity
+ Added model order.Order
+ Added model order.OrderNote
+ Added model order.CommunicationEvent
+ Added model order.ShippingAddress
+ Added model order.BillingAddress
+ Added model order.Line
+ Added model order.LinePrice
+ Added model order.LineAttribute
+ Added model order.ShippingEvent
+ Added model order.ShippingEventType
+ Added model order.PaymentEvent
+ Added model order.PaymentEventType
+ Added model order.OrderDiscount
Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate order
(oscardepends)lex@ubuntu:~/projects/oscardepends$ ./manage.py syncdb --migrate
Syncing...
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table south_migrationhistory
Creating table reviews_productreview
Creating table reviews_vote
Creating table thumbnail_kvstore

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no):
Please enter either "yes" or "no": no
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
Migrating...
Running migrations for analytics:
- Migrating forwards to 0001_initial.
> customer:0001_initial
> catalogue:0001_initial
> analytics:0001_initial
- Loading initial data for analytics.
Installed 0 object(s) from 0 fixture(s)
Running migrations for order:
- Migrating forwards to 0001_initial.
> order:0001_initial
FATAL ERROR - The following SQL query failed: ALTER TABLE "order_shippingaddress" ADD CONSTRAINT "country_id_refs_iso_3166_1_a2_6ed25861" FOREIGN KEY ("country_id") REFERENCES "address_country" ("iso_3166_1_a2") DEFERRABLE INITIALLY DEFERRED;
The error was: relation "address_country" does not exist

Error in migration: order:0001_initial
DatabaseError: relation "address_country" does not exist
```