English 中文(简体)
模型在合并时不制作表格
原标题:Models does not create tables when synched

我有几张扬戈模式供我扩大用户使用。 问题在于,在使用辛迪布时,该法典不会形成表格(简言之,没有发生任何情况)。 没有验证错误。 为什么发生这种情况? (这些模型在其他地方造成进口错误)

#!/usr/bin/env python
# encoding: utf-8
from django.db import models
from django.contrib.auth.models import User
from registration.signals import user_registered
from forms import ExtendedRegistrationForm
import hashlib

class InheritedProfile(models.Model):
    first_name = models.CharField("Name", max_length=50, blank=True, null=True)
    last_name = models.CharField("Last name", max_length=50, blank=True, null=True)
    pid = models.CharField("PESEL", max_length=11, blank=True, null=True)
    street = models.CharField("Street", max_length=50, blank=True, null=True)
    number = models.CharField("Flat/house number", max_length=10, blank=True, null=True)
    code = models.CharField("Zip ", max_length=6, blank=True, null=True)
    city = models.CharField("City", max_length=50, blank=True, null=True) 
    class Meta:
        abstract=True

class UserProfile(InheritedProfile):
    def upload_path(self, field_attname):
        filename = hashlib.md5(field_attname).hexdigest()[:4] + "_" + field_attname
        return "uploads/users/%s" % (filename,)

    user = models.ForeignKey(User, unique=True, related_name= profile )
    image = models.ImageField(upload_to=upload_path, verbose_name="Image", blank=True, null=True)

    class Meta:
        ordering = [ -id ]
        db_table =  userprofile 

    def __unicode__(self):
        return u"%s " % self.user.username

def user_created(sender, user, request, **kwargs):
    form = ExtendedRegistrationForm(request.POST)
    extended_user = UserProfile(user=user)
    extended_user.is_active = False
    extended_user.first_name = form.cleaned_data[ first_name ]
    extended_user.last_name = form.cleaned_data[ last_name ]
    extended_user.pid = form.cleaned_data[ pid ]
    extended_user.image = form.cleaned_data[ image ]
    extended_user.street = form.cleaned_data[ street ]
    extended_user.number = form.cleaned_data[ number ]
    extended_user.code = form.cleaned_data[ code ]
    extended_user.city = form.cleaned_data[ city ]
    extended_user.save()

user_registered.connect(user_created)

class Friend(InheritedProfile):
    friend_of = models.ForeignKey(UserProfile, related_name= friend_of )
    class Meta:
        db_table =  friend 

与此相反,本法典编制表格不成问题:

#!/usr/bin/env python
# encoding: utf-8
from django.db import models
from django.contrib.auth.models import User
import hashlib

class InheritedProfile(models.Model):
    first_name = models.CharField("Name", max_length=50, blank=True, null=True)
    last_name = models.CharField("Last name", max_length=50, blank=True, null=True)
    pid = models.CharField("PESEL", max_length=11, blank=True, null=True)
    street = models.CharField("Street", max_length=50, blank=True, null=True)
    number = models.CharField("Flat/house number", max_length=10, blank=True, null=True)
    code = models.CharField("Zip ", max_length=6, blank=True, null=True)
    city = models.CharField("City", max_length=50, blank=True, null=True) 
    class Meta:
        abstract=True

class UserProfile(InheritedProfile):
    def upload_path(self, field_attname):
        filename = hashlib.md5(field_attname).hexdigest()[:4] + "_" + field_attname
        return "uploads/users/%s" % (filename,)

    user = models.ForeignKey(User, unique=True, related_name= profile )
    image = models.ImageField(upload_to=upload_path, verbose_name="Image", blank=True, null=True)

    class Meta:
        ordering = [ -id ]
        db_table =  userprofile 

    def __unicode__(self):
        return u"%s " % self.user.username

class Friend(InheritedProfile):
    friend_of = models.ForeignKey(UserProfile, related_name= friend_of )
    class Meta:
        db_table =  friend 

我是否应当把这一用户重新定位在其他地方? 信号灯塔造成问题......

最佳回答

您似乎有某种类型的交叉进口;如果您进口一些模型到<代码>forms,并从中进口某种形式到models,这便可能无法解决,因为在处理<代码>models时,需要进口forms;forms要求>models。 ...... 这不能解决!

除此以外,我认为它设计得更好,不需要在模型模块中进口表格,因为它们与看法更相关!

问题回答

暂无回答




相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签