Re: unique not working as expected

28 views
Skip to first unread message

Amber Kulkarni

unread,
May 9, 2013, 7:47:46 AM5/9/13
to django...@googlegroups.com
I checked the table using python manage.py sql app_name
it shows the following

create table "tp_app_server" (
     "id " integer not null primary key,
      "link"  varchar(200) not null unique
      "crawled_flag" varchar(1) not null
)
;
COMMIT

Tom Evans

unread,
May 9, 2013, 9:23:42 AM5/9/13
to django...@googlegroups.com
That just shows the SQL Django would use to create the table, it says
nothing about how the table is currently constructed.

Use the .schema command in sqlite shell to see the current structure
of the table. Does it have a unique key on link?

Cheers

Tom

Amber Kulkarni

unread,
May 9, 2013, 10:59:00 AM5/9/13
to django...@googlegroups.com
Thanks Tom.
Got the problem.Problem solved on creating new model.



--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/LFzuzEo-g1o/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.





--
AMBER KULKARNI

C. Kirby

unread,
May 9, 2013, 12:48:11 PM5/9/13
to django...@googlegroups.com
Could you elaborate on what the resolution was for future people who may run into this problem?

Sam Solomon

unread,
May 10, 2013, 2:42:49 PM5/10/13
to django...@googlegroups.com
My guess is that unique=True was added after the table was created using syncdb.

I'm guessing that most companies that use Django professionally use South (http://south.aeracode.org/) to make schema changes easier.

Without South, you would have to keep the database in sync with the code manually (as in `CREATE INDEX...`)

With South, before you change the schema, you can follow these instructions: http://south.readthedocs.org/en/latest/convertinganapp.html#converting-an-app

After South has the existing structure synced in it's history, you can make schema changes and then create new migrations (python manage.py schemamigration --auto <app name>; python manage.py migrate)

Amber Kulkarni

unread,
May 11, 2013, 1:07:33 AM5/11/13
to django...@googlegroups.com
Yes , Sam is right.
unique=True was added after table was created.

Reply all
Reply to author
Forward
0 new messages