[英]operational error 1050 Error “Table already exists” in django makemigrations
Hi am getting this wherever i try to make changes to my models or trying to migrate am using mysql and django 1.8.6 嗨,我正在尝试对我的模型进行更改或尝试使用mysql和django 1.8.6进行迁移
operational error 1050 Error “Table 'products_myproducts' already exists” just every time i make migrations 操作错误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
also fo my products 也是我的产品
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"
this error causes when you delete migrations directory from your apps and not dropping the database tables. 当您从应用程序中删除迁移目录而不删除数据库表时,会出现此错误。
if data on the database is important, just backup form data and then drop the database tables. 如果数据库上的数据很重要,只需备份表单数据然后删除数据库表。
then delete all migrations directory from each app and makemigration then migrate again and import your data. 然后从每个应用程序中删除所有迁移目录,然后再迁移,然后再次迁移并导入数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.