ashok
ashok

Reputation: 43

How to delete Many-Many relationship between two models Django

class Question(models.Model):
      q_title = models.CharField(max_length=500)
      q_user = models.ForeignKey(MyUser, null=False, blank=False)
      q_slug = models.SlugField(null=True, blank=True)
      q_category=  models.ManyToManyField('Categories',null=True,blank=True)

class Categories(models.Model):
    category = models.CharField(max_length=200)

How do I delete q_category from Question Model. It gives me the error " Cannot alter field questions.Question.q_category into questions.Question.q_category - they are not compatible types (you cannot alter to or from M2M fields, or add or remove through= on M2M fields)"

Upvotes: 0

Views: 78

Answers (1)

Dariusz Krynicki
Dariusz Krynicki

Reputation: 2718

if you are still in development at the start of it just delete your db, delete your migrations and delete q_cateregory from Question model and re-create db again: run makemigrations, migrate and syncb.

Otherwise, just start from reading this: https://docs.djangoproject.com/en/1.8/ref/migration-operations/

Upvotes: 1

Related Questions