intermediate table in manytomany relationship not created

2010-08-05 Thread bksfu
Hi, I have the following model:

--
from django.db import models

class Phone(models.Model):
id = models.AutoField(primary_key=True, db_column='id')
type = models.CharField(max_length=1, db_column='Type',
null=False, blank=False)
status = models.CharField(max_length=1, db_column='Status',
null=False, blank=False)
country_code = models.CharField(max_length=3, db_column='Country',
blank=True)
area_code = models.CharField(max_length=3, db_column='AreaCode',
null=False, blank=False)
prefix = models.CharField(max_length=3, db_column='Prefix',
blank=True)
suffix = models.CharField(max_length=4, db_column='Suffix',
null=False, blank=False)

class Meta:
db_table = u'Phone'
app_label = u'testStuff'
db_tablespace = u'test'


class Room(models.Model):
id = models.AutoField(primary_key=True, db_column='id')
number = models.IntegerField(db_column='number', null=False,
blank=False)
building = models.CharField(max_length=5, db_column='Building',
null=False, blank=False)
type = models.CharField(max_length=1, db_column='Type',
null=False, blank=False)
campus = models.CharField(max_length=10, db_column='Campus',
null=False, blank=False)
phones = models.ManyToManyField(Phone, db_column='id', null=True)

class Meta:
db_table = u'Phone'
app_label = u'testStuff'
db_tablespace = u'test'
--

Next, I dropped the existing tables in my mysql db, then ran
'syncdb'.  The model tables were created, but not the intermediate
table. Adding phones & rooms are no problem, but I get an error when I
try to associate them, which states that the table 'Room_phones' does
not exist in the db.  I could manually create a 'through' table, I
guess, but shouldn't Django have created my intermediate table along
with the primary ones?  Thx for any help.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: intermediate table in manytomany relationship not created

2010-08-05 Thread bksfu
When Django created the above tables, they were created with the
MyISAM engine.  If the intermediate table has to have foreign keys
back to the Phone and Room tables, this would be illegal from MySQL's
perspective, which can apparently only form foreign key constraints
between InnoDB tables.  If this is the reason that the intermediate
table wasn't created, how do I force Django to create tables in MySQL
with the InnoDB engine?  - Brian

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: intermediate table in manytomany relationship not created

2010-08-06 Thread bksfu
Thanks, Carlos!

Brian

On Aug 5, 12:59 pm, Carlos Daniel Ruvalcaba Valenzuela
 wrote:
> There is an option to default to InnoDB tables on the configuration:
>
> http://docs.djangoproject.com/en/dev/ref/databases/#creating-your-tables
>
> Regards,
> Carlos Daniel Ruvalcaba Valenzuela
>
> On Thu, Aug 5, 2010 at 12:48 PM, bksfu  wrote:
> > When Django created the above tables, they were created with the
> > MyISAM engine.  If the intermediate table has to have foreign keys
> > back to the Phone and Room tables, this would be illegal from MySQL's
> > perspective, which can apparently only form foreign key constraints
> > between InnoDB tables.  If this is the reason that the intermediate
> > table wasn't created, how do I force Django to create tables in MySQL
> > with the InnoDB engine?  - Brian
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Django not creating intermediary tables for m2m relations

2010-08-06 Thread bksfu
Hi All,

When I run manage.py sqlall test, I get the proper MySQL create
statements for my models, (Phone,Room).
Room has a ManyToManyField(Phone) field, so I also get the proper
intermediate Room_phones table:

BEGIN;
CREATE TABLE `Phone` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY , blah, blah
);
CREATE TABLE `Room_phones` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`room_id` integer NOT NULL,
`phone_id` integer NOT NULL,
UNIQUE (`room_id`, `phone_id`)
);
ALTER TABLE `Room_phones` ADD CONSTRAINT `phone_id_refs_id_61361b28`
FOREIGN KEY (`phone_id`) REFERENCES `Phone` (`id`);
CREATE TABLE `Room` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY , blah, blah
);
ALTER TABLE `Room_phones` ADD CONSTRAINT `room_id_refs_id_71507c04`
FOREIGN KEY (`room_id`) REFERENCES `Room` (`id`);
COMMIT;

models.py contains:

class Phone(models.Model):
type = models.CharField(max_length=1, db_column='Type',
null=False, blank=False)
...

class Room(models.Model):
...
phones = models.ManyToManyField(Phone)

manage.py syncdb doesn't create the Room_phones table though. Just the
Room and Phone. I thought it would create it automagically, even
though I don't have a model in models.py for it??  I'm working with
MySQL, the db engine is set to InnoDB.  When I put the intermediary
table model explicitly in models.py and use the 'through' clause on
the ManyToManyField, there is no problem, syncdb works perfectly.  I
can do this, but ...

TIA, Brian

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django not creating intermediary tables for m2m relations

2010-08-10 Thread bksfu
Hi Xavier,

I had dropped my tables earlier, so this wasn't the problem.
Everything
was being created afresh, although there were existing tables in the
DB
that had nothing to do with my models.  All my existing tables had
different names
than the ones in my models.

On Aug 7, 2:55 am, Xavier Ordoquy  wrote:

> This will often happen when you have both model table created in the database 
> and then you add some field and syncdb.
> Syncdb will not perform operation on tables that are already created, 
> including created new fields or intermediate tables.
> However, if you start from scratch, this should be fine.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.