[sqlalchemy] missing constraint

2011-01-03 Thread dhanil anupurath
Hi

My app is using SQLAlchemy0.5.6.
I have a class defined as follows.

class EmailSetup(DeclarativeBase):
__tablename__ = 'emailsetup'
id = Column(Unicode(50), primary_key=True)
mail_server=Column(Unicode(255))
description=Column(String(200))
port = Column(Integer)
use_secure = Column(Integer) #No, TLS, SSL
site_id = Column(Unicode(50),
ForeignKey('sites.id',onupdate=CASCADE, ondelete=CASCADE))
credential=relation(Credential, \
primaryjoin=id == Credential.entity_id,\
foreign_keys=[Credential.entity_id],\
uselist=False,cascade='all, delete, delete-
orphan')


this works fine on ubuntu installation . (MySQL 5.1.37)
it creates foreign constraint to the sites table.

CREATE TABLE `emailsetup` (
  `id` varchar(50) NOT NULL,
  `mail_server` varchar(255) DEFAULT NULL,
  `description` varchar(200) DEFAULT NULL,
  `port` int(11) DEFAULT NULL,
  `use_secure` int(11) DEFAULT NULL,
  `site_id` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `site_id` (`site_id`),
  CONSTRAINT `emailsetup_ibfk_1` FOREIGN KEY (`site_id`) REFERENCES
`sites` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8


But in centos (MySQL 5.0.77) , the foreign key constraint is missing
when i check with a show create table.

CREATE TABLE `emailsetup` (
  `id` varchar(50) NOT NULL,
  `mail_server` varchar(255) default NULL,
  `description` varchar(200) default NULL,
  `port` int(11) default NULL,
  `use_secure` int(11) default NULL,
  `site_id` varchar(50) default NULL,
  PRIMARY KEY  (`id`),
  KEY `site_id` (`site_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

any idea what is happening
Is this an issue related to SA or MySQL?

Thanks

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



Re: [sqlalchemy] missing constraint

2011-01-03 Thread Michael Bayer
That's certainly related to the version of MySQL in use, assuming you're 
executing the exact same Python code against both backends.

The first thing to do here is to turn on echo=True, look at the SQL sqlalchemy 
emits, and begin testing those specific clauses against the MySQL database 
manually to see if the results continue to differ.   This would confirm the 
behavior is related to MySQL and you can start researching to see what that's 
about.


On Jan 3, 2011, at 9:35 AM, dhanil anupurath wrote:

 Hi
 
 My app is using SQLAlchemy0.5.6.
 I have a class defined as follows.
 
 class EmailSetup(DeclarativeBase):
__tablename__ = 'emailsetup'
id = Column(Unicode(50), primary_key=True)
mail_server=Column(Unicode(255))
description=Column(String(200))
port = Column(Integer)
use_secure = Column(Integer) #No, TLS, SSL
site_id = Column(Unicode(50),
 ForeignKey('sites.id',onupdate=CASCADE, ondelete=CASCADE))
credential=relation(Credential, \
primaryjoin=id == Credential.entity_id,\
foreign_keys=[Credential.entity_id],\
uselist=False,cascade='all, delete, delete-
 orphan')
 
 
 this works fine on ubuntu installation . (MySQL 5.1.37)
 it creates foreign constraint to the sites table.
 
 CREATE TABLE `emailsetup` (
  `id` varchar(50) NOT NULL,
  `mail_server` varchar(255) DEFAULT NULL,
  `description` varchar(200) DEFAULT NULL,
  `port` int(11) DEFAULT NULL,
  `use_secure` int(11) DEFAULT NULL,
  `site_id` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `site_id` (`site_id`),
  CONSTRAINT `emailsetup_ibfk_1` FOREIGN KEY (`site_id`) REFERENCES
 `sites` (`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
 
 
 But in centos (MySQL 5.0.77) , the foreign key constraint is missing
 when i check with a show create table.
 
 CREATE TABLE `emailsetup` (
  `id` varchar(50) NOT NULL,
  `mail_server` varchar(255) default NULL,
  `description` varchar(200) default NULL,
  `port` int(11) default NULL,
  `use_secure` int(11) default NULL,
  `site_id` varchar(50) default NULL,
  PRIMARY KEY  (`id`),
  KEY `site_id` (`site_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
 
 any idea what is happening
 Is this an issue related to SA or MySQL?
 
 Thanks
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to 
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/sqlalchemy?hl=en.
 

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