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.


On Saturday, 14 July, 2018 07:05 PM, mottaz hejaze wrote:
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.

On Fri, 13 Jul 2018, 22:24 , <lissandratheg...@gmail.com <mailto:lissandratheg...@gmail.com>> wrote:

    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 models

    class 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+unsubscr...@googlegroups.com
    <mailto:django-users+unsubscr...@googlegroups.com>.
    To post to this group, send email to django-users@googlegroups.com
    <mailto:django-users@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
    
<https://groups.google.com/d/msgid/django-users/6f546243-23f0-4760-806b-9fff01d2afd7%40googlegroups.com?utm_medium=email&utm_source=footer>.
    For more options, visit https://groups.google.com/d/optout.

--
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+unsubscr...@googlegroups.com <mailto:django-users+unsubscr...@googlegroups.com>. To post to this group, send email to django-users@googlegroups.com <mailto:django-users@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/CAHV4E-eGQQ3jdwSaa9d9xaxk7rV_Tt-Fqas3OTuhYEYd1%3D8zMA%40mail.gmail.com <https://groups.google.com/d/msgid/django-users/CAHV4E-eGQQ3jdwSaa9d9xaxk7rV_Tt-Fqas3OTuhYEYd1%3D8zMA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/1cc82de7-c0af-527f-93f8-2740c46a9001%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to