On Sat, 2008-03-08 at 19:18 -0600, Michael Hipp wrote:
> I have a legacy database that happens to be PostgreSQL. It has this primary 
> key field:
> 
>      CREATE TABLE foo (
>          id integer PRIMARY KEY,
> 
> When I do 'inspectdb' it gives me a model with this in it:
> 
>      class Foo(models.Model):
>          id = models.IntegerField(primary_key=True)
> 
> But what I really want to end up with, I think, is this:
> 
>      class Foo(models.Model):
>          id = models.AutoField(primary_key=True)
> 
> Is there any way to get inspectdb to provide this instead of IntegerField?

You would have to modify the particular database backend's inspectdb
file to do whatever introspection is needed to determine that that
particular field is an automatically incremented one. Since it's
possible to have more than one auto-incremented field in a database
table and since they're not always the primary key, this isn't something
Django can infer manually.

> The legacy database is in flux (all 1300+ fields) so just hand editing it 
> every time it changes isn't practical right now.

So write a script that post-processes the regular output and makes this
change.

Malcolm

-- 
On the other hand, you have different fingers. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to