Ticket #22275: dj_unique_together.sh

File dj_unique_together.sh, 900 bytes (added by Ryan Hiebert, 11 years ago)

Shell script that demonstrates unique_together issue

Line 
1# Demonstrate an issue with the new Django migrations
2# and the unique_together setting with foriegn keys.
3
4# Requires that the tip of Django is already installed.
5
6# Die on error
7set -e
8
9# Create a new project called 'spam'
10django-admin startproject spam
11
12# Go into the new project
13cd spam
14
15# Create a new app called 'eggs'
16django-admin startapp eggs
17
18# Add the new app to settings.py
19cat >> spam/settings.py <<EOF
20INSTALLED_APPS = 'eggs',
21EOF
22
23# Create the basic failing models
24cat > eggs/models.py <<EOF
25from django.db import models
26
27class Knight(models.Model):
28 pass
29
30class Rabbit(models.Model):
31 class Meta:
32 unique_together = (('knight', 'parent'),)
33 knight = models.ForeignKey(Knight)
34 parent = models.ForeignKey('self', related_name='children')
35EOF
36
37# Create the migrations
38python manage.py makemigrations
39
40# Apply the migrations
41python manage.py migrate --no-initial-data
Back to Top