I tried for hours to get django's migrate/makemigrations function work but miserably couldn't so I created my tables in MySQL. Now I'm trying to add a ManyToManyField between 2 models but am not sure how the MySQL syntax is supposed to look like.--This is my current code:from django.db import modelsclass Publication(models.Model):title = models.CharField(max_length=30)class Article(models.Model):headline = models.CharField(max_length=100)and I can create a table as follows in MySQL:CREATE TABLE publication (title varchar(30));CREATE TABLE Article (headline varchar(100),);I need to add the ManyToManyField like so:class Article(models.Model):headline = models.CharField(max_length=100)publications = models.ManyToManyField(Publication)I'm really running low on time, could someone assist me with what the MySQL code is supposed to look like? I will be permanently in your debt.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6f546243-23f0-4760-806b-9fff01d2afd7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
When looking at my database it has the 3rd table for the
ManyToMany with the following:
1. ID auto-generated,
2. Table1.ID
3. Table2.ID.
All fields will be integers.
The 3rd table will be named Table1_Table2 or something like that.
I noticed in your code below that you do not have an ID field on any table. I believe this is required for M2M tables. Django makemigrations & migrate will generate this for you if not defined in the model. Django will also create the third table for you with makemigrations/migrate so no need to create it by hand.
What were the problems you were having with
makemigrations/migrate? It is supposed to create the tables for
all apps in your project but you can also specify only 1 app if
you want to.
Hope this helps.
for many to many relationships between two tables .. you can make a third table that only contains the id fields ftom both tables , then you can make a third model for this table.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHV4E-eGQQ3jdwSaa9d9xaxk7rV_Tt-Fqas3OTuhYEYd1%3D8zMA%40mail.gmail.com.