On Nov 10, 5:23 pm, octopusgrabbus <old_road_f...@verizon.net> wrote:
> I have an existing MySQL table. It's fairly straightforward:
>
> part_num char(20)
> ept_type smallint (default 0) not null
> inv_id integer (default 0) not null
> load_date date
>
> columns 2 and 3 (ept_type and inv_id) form a unique key. An example of
> a  unique key is 43 and 80581770.
>
> I've tried to create a model
>
> from django.db import models
>
> # Create your models here.
> class ept_inv(models.Model):
>     part_num = models.CharField(max_length=20)
>     ept_type = models.SmallIntegerField
>     inv_id = models.IntegerField
>     load_date = models.DateField
>
> but am getting errors on syncdb
>     class ept_inv(models.Model):
>   File "/usr/local/lib/python2.6/site-packages/django/db/models/
> base.py", line 9
> 2, in __new__
>     new_class.add_to_class(obj_name, obj)
>   File "/usr/local/lib/python2.6/site-packages/django/db/models/
> base.py", line 2
> 12, in add_to_class
>     value.contribute_to_class(cls, name)
> TypeError: Error when calling the metaclass bases
>     unbound method contribute_to_class() must be called with
> SmallIntegerField i
> nstance as first argument (got ModelBase instance instead)
>
> What should I be doing?
> Thank you.

All your fields need to be instances, not classes - eg
SmallIntegerField() not SmallIntegerField.

Also note that Django has built-in functionality for building a model
from an existing table: just run ./manage.py inspectdb
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.

Reply via email to