[英]MySQL Error 1146 and 1050 - Table does not exists and Table already exists
[英]operational error 1050 Error “Table already exists” in django makemigrations
嗨,我正在嘗試對我的模型進行更改或嘗試使用mysql和django 1.8.6進行遷移
操作錯誤1050錯誤“表'products_myproducts'已經存在”,每次我進行遷移
class Product(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL) managers = models.ManyToManyField(settings.AUTH_USER_MODEL,related_name="managers_product",blank=True) media = models.ImageField(blank=True,null=True, upload_to=download_media_location, storage=FileSystemStorage(location=settings.PROTECTED_ROOT)) title = models.CharField(max_length=30) description = models.TextField(default='',blank=True) slug= models.SlugField(blank=True,unique=True) price = models.DecimalField(max_digits=60,decimal_places=2,default=9.99) sale_active = models.BooleanField(default=False) sale_price = models.DecimalField(max_digits=60,decimal_places=2,default=6.99,null=True,blank=True) def __str__(self): return self.title
也是我的產品
class MyProducts(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL) products = models.ManyToManyField(Product,blank=True) def __str__(self): return "%s" %(self.products.count()) class Meta: verbose_name = "My Products" verbose_name_plural = "My Products"
當您從應用程序中刪除遷移目錄而不刪除數據庫表時,會出現此錯誤。
如果數據庫上的數據很重要,只需備份表單數據然后刪除數據庫表。
然后從每個應用程序中刪除所有遷移目錄,然后再遷移,然后再次遷移並導入數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.