简体   繁体   中英

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

operational error 1050 Error “Table 'products_myproducts' already exists” just every time i make migrations

 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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