django model and sqlite db creation bug

ぃ、小莉子 提交于 2020-01-05 05:26:35

问题


I have the following model.

from django.db import models

class Client(models.Model):
    postcode = models.CharField(max_length=10)  
    first_name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)
    address = models.TextField(blank=True)
    phone = models.IntegerField(blank=True)
    email = models.EmailField(blank=True)
    url = models.URLField(blank=True)
    client_since = models.DateTimeField('Client Since')

    def __unicode__(self):
        return self.first_name

def client_since(self):
    return self.client_since.date() == datetime.date.today()

class Contractor(models.Model):
   postcode = models.CharField(max_length=10)   
   first_name = models.CharField(max_length=100)
   last_name = models.CharField(max_length=100)
   address = models.TextField(blank=True)
   phone = models.IntegerField(blank=True)
   email = models.EmailField(blank=True)
   contractor_since = models.DateTimeField('Contractor Since')

   def __unicode__(self):
       return self.first_name

   def contractor_since(self):
       return self.contractor_since.date() == datetime.date.today()

I run 'python manage.py validate' gives me - 0 errors found

Then I run 'python manage.py sql "appname" and I get to see my tables...

BEGIN;
CREATE TABLE "schedule_client" (
    "id" integer NOT NULL PRIMARY KEY,
    "postcode" varchar(10) NOT NULL,
    "first_name" varchar(100) NOT NULL,
    "last_name" varchar(100) NOT NULL,
    "address" text NOT NULL,
    "phone" integer NOT NULL,
    "email" varchar(75) NOT NULL,
    "url" varchar(200) NOT NULL,
    "client_since" datetime NOT NULL
 )
 ;
 CREATE TABLE "schedule_contractor" (
     "id" integer NOT NULL PRIMARY KEY,
     "postcode" varchar(10) NOT NULL,
     "first_name" varchar(100) NOT NULL,
     "last_name" varchar(100) NOT NULL,
     "address" text NOT NULL,
     "phone" integer NOT NULL,
     "email" varchar(75) NOT NULL
 )
 ;
 COMMIT;

But I don't see "contracor_since in the contractor table ... db field being created??? I tried several times, I am using django 1.1.1 on OS X leopard.

What I am doing wrong?


回答1:


You are shadowing the model attribute by a function definition using the same name. Try change either the function name or your model attribute (contractor_since).



来源:https://stackoverflow.com/questions/2139021/django-model-and-sqlite-db-creation-bug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!