繁体   English   中英

操作错误1050 django makemigrations中的“表已存在”错误

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM