2017-07-08 90 views
-1

我創建了一個Django應用程序,並添加models.py一些示範田表myapp_tableName已經存在

1.logo

2.shirt

及其屬性 PID,名稱和org 然後我給他們添加了一個新的屬性價格。並執行命令python manage.py makemigrations和python manage.py遷移我得到了錯誤'表buapp_dealer已經存在。

這裏是我的models.py

from django.db import models 

# Create your models here. 

class founder(models.Model): 
    name=models.CharField(max_length=30) 
    address=models.CharField(max_length=50) 
    country=models.CharField(max_length=20) 
    email=models.EmailField(null=True) 
    headshot=models.ImageField(upload_to='images',null=True) 
    def __str__(self): 
     return self.name 
    __repr__=__str__ 

class supporter(models.Model): 
    name=models.CharField(max_length=30) 
    address=models.CharField(max_length=20) 
    email=models.EmailField(null=True) 
    headshot=models.ImageField(upload_to='images',null=True) 
    def __str__(self): 
     return self.name 
    __repr__=__str__ 

    class Admin: 
     list_display=('name','address','email') 


class dealer(models.Model): 
    name=models.CharField(max_length=30) 
    address=models.CharField(max_length=40) 
    #city=models.CharField(max_length=60) 
    country=models.CharField(max_length=50) 
    website=models.URLField(null=True) 
    rep=models.IntegerField(null=True) 
    def __str__(self): 
     return self.name 
    __repr__=__str__ 

    class Admin: 
     list_display=('name','address','country') 
     list_filter=('name','country') 
     ordering=('rep',) 
     search_fields=('name') 

class tshirt(models.Model): 
    price=models.FloatField(default=0.0) 
    name=models.CharField(max_length=50,default='default') 
    fontimage=models.ImageField(upload_to='images/tshirts',null=True) 
    backimage=models.ImageField(upload_to='images/tshirts',null=True) 
    def __str__(self): 
     return str(self.pid) 
    __repr__=__str__ 
    class Admin: 
     list_display=('pid','price','fontimage') 
     list_filter=('price') 
     ordering=('-pid') 
     search_fields=('name') 



class logo(models.Model): 
    pid=models.IntegerField() 
    price=models.FloatField(default=0.0) 
    org=models.CharField(max_length=50) 
    img=models.ImageField(upload_to='images/tshirts',null=True) 
    def __str__(self): 
     return str(self.pid) 
    __repr__=__str__ 
    class Admin: 
     list_display=('pid','price','img') 
     list_filter=('price') 
     ordering=('-pid') 
     search_fields=('org') 

class final(models.Model): 
    pid=models.IntegerField() 
    price=models.FloatField(default=0.00) 
    fontimg=models.ImageField(upload_to='images/finals',null=True) 
    backimg=models.ImageField(upload_to='images/finals',null=True) 
    def __str__(self): 
     return str(self.pid) 
    __repr__=__str__ 
+0

什麼'manage.py migrate'的輸出? –

+0

您是否嘗試過修改'python manage.py migrate'? – badiya

+0

嘗試發佈模型代碼,最新的並且發佈你的追蹤 – Exprator

回答

0

選擇是否加入域(價格)實際上是在數據庫中,然後讓你的數據庫的備份並嘗試運行這個(用於應用程序的名字buapp_dealer)

python manage.py migrate --fake buapp_dealer 

這將標記遷移完成。

0

解決的辦法是:

python manage.py makemigrations 

python manage.py migrate --fake buapp_dealer 

python manage.py migrate 

應該解決您的問題