我正在尝试添加"订单"字段给用户,该用户是类Order的外键。 Order对OrderItem类有一个外键。 OrderItem有一个OneToOneField到另一个应用程序的类Store Item。我用south来迁移数据库。我不相信错误是数据库迁移的方式。我收到了操作错误,"错误:没有这样的表:webstore_storeitem"。任何帮助将不胜感激。谢谢。
from django.contrib.auth.models import User
from django.db import models
from loginRouter import *
class OrderItem(models.Model):
itemCost = models.DecimalField(max_digits=16,decimal_places=2)
itemQuantity = models.IntegerField()
itemID = models.OneToOneField('webstore.StoreItem')
def __unicode__(self):
return self.itemID.itemName
class Order(models.Model):
orderDate = models.DateTimeField('Order Date')
shippingCost = models.DecimalField(max_digits=16,decimal_places=2)
totalCost = models.DecimalField(max_digits=16,decimal_places=2)
item = models.ForeignKey(OrderItem)
def __unicode__(self):
return unicode(self.item)
class UserProfile(models.Model):
user = models.OneToOneField(User)
confirmation_code = models.CharField(max_length=128)
reset_code = models.CharField(max_length=128)
address_lineOne = models.CharField(max_length=128)
address_lineTwo = models.CharField(max_length=128)
city = models.CharField(max_length=128)
State = models.CharField(max_length=128)
zipCode = models.CharField(max_length=10)
orders = models.ForeignKey(Order)
def __unicode__(self):
return self.user.username
我在南方做了什么:
before Change:
$./manage.py schemamigration login --initial
after change:
$./manage.py schemamigration login --auto
$./manage.py migrate login --fake
$./manage.py migrate login
webstore.Models:
from django.db import models
from imagekit.models import ProcessedImageField
from imagekit.processors import ResizeToFill
class StoreCategory(models.Model):
categoryName = models.CharField(max_length=128)
def __unicode__(self):
return self.categoryName
class StoreItem(models.Model):
category = models.ForeignKey(StoreCategory)
itemName = models.CharField(max_length=128)
itemNameid = models.CharField(max_length=128)
description = models.CharField(max_length=2048)
price = models.DecimalField(max_digits=16,decimal_places=2)
quantity = models.IntegerField(default=0)
picture = ProcessedImageField(upload_to='avatars',
processors=[ResizeToFill(250, 185)],
format='JPEG',
options={'quality': 60})
featured_picture = ProcessedImageField(upload_to='avatars',
processors=[ResizeToFill(800, 300)],
format='JPEG',
options={'quality': 60})
isFeatured = models.BooleanField(default=False)
def __unicode__(self):
return self.itemName
答案 0 :(得分:0)
问题是每个应用程序都在使用单独的数据库。我合并了它们,这解决了我遇到的问题。