On Tue, 2006-06-27 at 15:25 -0700, bahund wrote: > Hi, > > I have the following model which has a foreign key field that I would > like to be null at times: > > class Car(models.Model): > make = models.CharField(maxlength=100, core=True) > model = models.CharFeild(maxlength=100, core=True) > date = models.DateTimeField(auto_now_add=True) > forum = models.ForeignKey(Forum, blank=True, null=True) > > Even with the "blank=True" and "null=True" arguments it still will not > allow inserts. I've tried a combination of these two arguments (just > one or the other) and that didn't work either. I found the following > post and it seemed to work for them so I'm wondering if anyone can see > the problem with my situation. > > http://groups.google.com/group/django-users/browse_thread/thread/ff921044d994f336/a42316a8049e8c6d?q=null+foreign+key&rnum=10#a42316a8049e8c6d > > The admin is kicking back the following error: > > ERROR: null value in column "forum_id" violates not-null constraint > INSERT INTO "search_car" ("make","model","date","forum_id") VALUES > ('VW','Jetta','2006-06-27 23
I would guess you initially created the model without the null = True and then ran syncdb. That will create the relevant database column with a "NOT NULL" constraint (have a look at the *_car table in your database to check this. Since "null = True" affects the database (by permitting the column to be nullable), you need to fix the SQL for that model. Either use "./manage.py reset <appname>" if you can afford to lose the data already in the tables, or run "./manage.py sql <appname>", look at what the column should be and create the appropriate "ALTER TABLE..." SQL commands that you apply by hand. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---