Re: How to deal with an auto-incrementing primary key
If you are absolutely sure the field is filled in (the sequence is defined) I guess you can allow it to be null in the model definition. On Tue, May 10, 2011 at 7:33 PM, wilburwrote: > Using exclude works to eliminate this sample_id field from the form, > but I get a > > 'Null value in column "sample_id" violates not-null constraint' > > If one inserts a record directly through Postgresql command line, the > sample_id field gets incremented automatically with its sequence, but > it does not do so when adding a new record with the Django form... > > On May 10, 10:19 am, Shawn Milochik wrote: >> http://docs.djangoproject.com/en/1.3/ref/contrib/admin/ >> >> Check out 'fields' and 'exclude.' > > -- > 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 > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to deal with an auto-incrementing primary key
> > Will south add in the new ID field? I have never come across a situation where South was not able to change something in a table for me, so far. Try it please. On Tue, May 10, 2011 at 1:52 PM, wilburwrote: > I definitely need to keep the database, and have South installed, but > should I get rid of the original primary key and the sequence it > depends on? Will south add in the new ID field? > > On May 10, 11:48 am, Shawn Milochik wrote: > > If you don't mind losing all your data you can destroy the database then > > do syncdb. > > > > If you re-run syncdb without re-creating the database then it will do > > nothing for existing tables. > > > > You can use South[1] if you need to keep your data intact. > > > > [1]http://south.aeracode.org/ > > -- > 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 > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- AJ -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to deal with an auto-incrementing primary key
I definitely need to keep the database, and have South installed, but should I get rid of the original primary key and the sequence it depends on? Will south add in the new ID field? On May 10, 11:48 am, Shawn Milochikwrote: > If you don't mind losing all your data you can destroy the database then > do syncdb. > > If you re-run syncdb without re-creating the database then it will do > nothing for existing tables. > > You can use South[1] if you need to keep your data intact. > > [1]http://south.aeracode.org/ -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to deal with an auto-incrementing primary key
If you don't mind losing all your data you can destroy the database then do syncdb. If you re-run syncdb without re-creating the database then it will do nothing for existing tables. You can use South[1] if you need to keep your data intact. [1] http://south.aeracode.org/ -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to deal with an auto-incrementing primary key
I will try just removing it from the model. Does this mean I should remove the sample_id variable from the Postgres database as well. Will running syncdb create the new id field for that table? On May 10, 10:33 am, wilburwrote: > Using exclude works to eliminate this sample_id field from the form, > but I get a > > 'Null value in column "sample_id" violates not-null constraint' > > If one inserts a record directly through Postgresql command line, the > sample_id field gets incremented automatically with its sequence, but > it does not do so when adding a new record with the Django form... > > On May 10, 10:19 am, Shawn Milochik wrote: > > >http://docs.djangoproject.com/en/1.3/ref/contrib/admin/ > > > Check out 'fields' and 'exclude.' -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to deal with an auto-incrementing primary key
I think the problem is that you used IntegerField instead of AutoField. http://docs.djangoproject.com/en/1.3/ref/models/fields/#autofield However, why even bother? Why not get rid of that field and use the built-in id field that you're going to get from a Django model? There's no benefit at all -- you're just duplicating what would happen automatically. Plus, it's causing you all this trouble and wasting your time. Shawn -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to deal with an auto-incrementing primary key
Thanks for helping on this Shawn... My model definition looks like this: class Sample(models.Model): met_type = models.ForeignKey(MetType, verbose_name='Meteorite Type') sample_name = models.CharField(max_length=100, verbose_name='Sample Name') sample_id = models.IntegerField(primary_key=True, verbose_name='Sample ID') location = models.CharField(max_length=100,blank=True,null=True, verbose_name='Location') fall_date = models.CharField(max_length=20,blank=True,null=True, verbose_name='Fall Date') objects=models.Manager() class Meta: db_table = u'sample' ordering = ['sample_name'] def __unicode__(self): #return unicode(self.sample_name) return self.sample_name On May 10, 11:10 am, Shawn Milochikwrote: > What's your model look like? > > Did you add the foreign_key = True kwarg to the field in question? -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to deal with an auto-incrementing primary key
What's your model look like? Did you add the foreign_key = True kwarg to the field in question? -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to deal with an auto-incrementing primary key
Using exclude works to eliminate this sample_id field from the form, but I get a 'Null value in column "sample_id" violates not-null constraint' If one inserts a record directly through Postgresql command line, the sample_id field gets incremented automatically with its sequence, but it does not do so when adding a new record with the Django form... On May 10, 10:19 am, Shawn Milochikwrote: > http://docs.djangoproject.com/en/1.3/ref/contrib/admin/ > > Check out 'fields' and 'exclude.' -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to deal with an auto-incrementing primary key
http://docs.djangoproject.com/en/1.3/ref/contrib/admin/ Check out 'fields' and 'exclude.' -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.