Re: Django Not Populating AutoField

2011-08-19 Thread Landy Chapman


On Aug 19, 2:05 pm, Lee  wrote:
> Landy - thanks for that idea. Am I correct in understanding that
> setting a field to AutoField has no effect on save_model, and simply
> causes dbsync to add the sequence/nextval to the Postgres table?

I am not sure; On a droid phone so I can't look at the source code or
run tests.

> If so
> that is my problem, because I want to have one database schema that
> works across different DBMSes, and the sequence/nextval syntax is
> Postgres-specific so I have not been using dbsync.

Django abstracts this away.. If django is creating your tables, you
can trust it will do The Right Thing(tm)  for whatever DBMS you are
using.  If you're not the trusting type you can run this command to
find out what django would do to create your tables:
   django-admin.py sqlall

Then you can change the database_backend  in settings.py to find out
what the differences would be.

> I was hoping AutoField caused the *application* to manage the auto-
> incrementing primary key, not the database -- is there an easy way to
> do this in Django/Admin?
That is almost never a good idea (*maybe* there is an edge case I've
never seen).  It isn't easy to prevent collisions (two records with
same id). Imagine two users adding new records at the same time. Why
do that when the problem is already solved by your DBMS?

> Thanks very much for the help.
You're quite welcome!

-- 
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: Django Not Populating AutoField

2011-08-19 Thread Lee
Landy - thanks for that idea. Am I correct in understanding that
setting a field to AutoField has no effect on save_model, and simply
causes dbsync to add the sequence/nextval to the Postgres table? If so
that is my problem, because I want to have one database schema that
works across different DBMSes, and the sequence/nextval syntax is
Postgres-specific so I have not been using dbsync.

I was hoping AutoField caused the *application* to manage the auto-
incrementing primary key, not the database -- is there an easy way to
do this in Django/Admin?

Thanks very much for the help.

Lee

-- 
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: Django Not Populating AutoField

2011-08-19 Thread Landy Chapman
Did you create the table using django?
Can you post the table definition in postgresql?

If you still have an empty database, you could try dropping the id
column and  do a django  dbsync

otherwise you may have to create a sequence and apply it to the id
field. Something along the lines of:

create sequence id_seq start 1 increment 1;
alter table xxx alter column id set default nextval('id_seq');

-- 
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: Django Not Populating AutoField

2011-08-19 Thread Lee
<>

Did so -- no effect. I even disabled my overridden save_model so I'm
back to out-of-the-box Admin setup -- no effect. This is with Postgres
and the psycopg2 driver. Is no one else seeing this problem?

On Aug 18, 5:32 pm, Shawn Milochik  wrote:
> As defined your id field doesn't differ from Django's default. Just get
> rid of your custom id field.

-- 
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: Django Not Populating AutoField

2011-08-18 Thread Shawn Milochik
As defined your id field doesn't differ from Django's default. Just get 
rid of your custom id field.



--
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.



Django Not Populating AutoField

2011-08-18 Thread Lee Hughes
In my model I have

id = models.AutoField(primary_key=True)

but upon saving a new record I get

null value in column "id" violates not-null constraint

I suspect this may be caused by my overriding save_model in admin.py to
populate timestamp fields:

  def save_model(self, request, obj, form, change):
if change:
  obj.updated_by = request.user.username
else:
  obj.created_by = request.user.username
obj.save()

Any ideas on how to restore the AutoField functionality?

Thanks-

-- 
Lee

-- 
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.