I create following with MySQL & phpmyadmin :

CREATE TABLE `os_platform` (
  `id` int NOT NULL auto_increment,
  `op_name` varchar(64) NOT NULL,
  PRIMARY KEY  (`opid`)
)

CREATE TABLE `product` (
  `id` int NOT NULL auto_increment,
  `name` varchar(64) NOT NULL,
  `os_platform_id` int NOT NULL,
  PRIMARY KEY  (`pid`),
  KEY `os_platform_id` (`os_platform_id`),
  CONSTRAINT `product_ibfk_1` FOREIGN KEY (`os_platform_id`)
REFERENCES `os_platform` (`os_platform_id`) ON DELETE CASCADE ON
UPDATE CASCADE
)


and this is create by django :

l...@shuge ~/fap_soft $ cat fap/models.py
from django.db import models
class OS_Platform(models.Model):
    op_name = models.CharField(max_length=64, unique=True)
    def __unicode__(self):
        return self.op_name
    class Meta:
        db_table = "os_platform"
class Product(models.Model):
    name = models.CharField(max_length=64, unique=True)
    os_platform = models.ForeignKey(OS_Platform)
    def __unicode__(self):
        return self.name
    class Meta:
        db_table = "product"

l...@shuge ~/fap_soft $ python manage.py sqlall fap
BEGIN;
CREATE TABLE `os_platform` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `op_name` varchar(64) NOT NULL UNIQUE
)
;
CREATE TABLE `product` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `name` varchar(64) NOT NULL UNIQUE,
    `os_platform_id` integer NOT NULL
)
;
ALTER TABLE `product` ADD CONSTRAINT os_platform_id_refs_id_3f3a2784
FOREIGN KEY (`os_platform_id`) REFERENCES `os_platform` (`id`);
CREATE INDEX `product_os_platform_id` ON `product` (`os_platform_id`);
COMMIT;


It seems that official docs hasn't give a reference to howto define
'ON DELETE CASCADE ON UPDATE CASCADE' in models,
so, is there a bug in http://docs.djangoproject.com/en/dev/topics/db/models/
?

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

Reply via email to