Question

I have created a model and done the "syncdb" operation. It was executed fine. Also I had inserted many records to that model, then I created one more model which needs to be connected as M2M for the previous model.

Models.py

class Topic(models.Model):
      name = models.CharField(max_length=200)
      description = models.TextField()

I have done this model and executed syncdb also I inserted many records for this model

I am adding one more model

class BusinessUnit(models.Model):
      name = models.CharField(max_length=300)
      user = models.OneToOneField(User,primary_key=True)

Then,I have designed the 'Topic' for the requirement

class Topic(models.Model):
  name = models.CharField(max_length=200)
  description = models.TextField()
  business_unit = models.ManyToManyField(BusinessUnit)

Here I wanna do the operations behind of This dynamic M2M relationship manually.

Here what are the steps I need to do manually for this dynamically added M2M relationship field(business_unit) in 'Topic' like creating dbs? Indexing, relationship etc..?

This would be easy whenever I need to add some field dynamically for the existing model?

Était-ce utile?

La solution

You can see the SQL that Django uses to create the models by running python manage.py sqlall <appname>. The easiest way to alter the database is to grab the SQL that represents your modifications and run it against the database; you can get a database shell by running python manage.py dbshell.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top