WebFaction
Community site: login faq

I have a field in the model like this:

class SomeModel(models.Model):
    #...
    something = models.ForeignKey(User, related_name='something_else')

It's created in MySQL database with "NOT NULL" constraint. Now I need it to be null-able. Therefore I change the model like this:

something = models.ForeignKey(User, related_name='something_else', null=True)

As I understand, Django "syncdb" can't handle this. So what's the easiest way to do this on Webfaction (without losing the data)?

asked 20 Oct '10, 18:32

nuigurumi
381610
accept rate: 0%

edited 20 Oct '10, 18:33


First, I would look into using South as a schema migration tool. That will help make schema changes easier in the future. And, its pretty easy to use once you get the hang of it.

To remove the NOT NULL constraint from that column, I would use a a SQL statement like the one below since MySQL columns are NULL by default

ALTER TABLE myapp_somemodel MODIFY somecolumn INTEGER;

I'm not sure if you will need to re-build the foreign key constraint on the DB or not...

See this post on Stackoverflow.

permanent link

answered 20 Oct '10, 18:55

jlmurphy
161
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×168

question asked: 20 Oct '10, 18:32

question was seen: 6,627 times

last updated: 20 Oct '10, 18:55

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM