in reply to Re^2: dbicdump and relationships
in thread dbicdump and relationships
I see that DBIx::Class::Schema::Loader::DBI::mysql uses SHOW CREATE TABLE to get table definition, and then looking for
to get information about foreign keys. I tried to create some tables in mysql and check the output of SHOW CREATE TABLES:CONSTRAINT ... FOREIGN KEY ... REFERENCES ...
mysql> create table foo (id integer primary key, name varchar(10)); Query OK, 0 rows affected (0.01 sec) mysql> create table boo (id integer primary key, foo_id integer refere +nces foo(id)); Query OK, 0 rows affected (0.00 sec) mysql> create table bar (id integer primary key, foo_id integer, const +raint foo_id_fk foreign key (foo_id) references foo(id)); Query OK, 0 rows affected (0.00 sec) mysql> show create table boo; +-------+------------------------------------------------------------- +--------------------------------------------------------------------- +----------+ | Table | Create Table + + | +-------+------------------------------------------------------------- +--------------------------------------------------------------------- +----------+ | boo | CREATE TABLE `boo` ( `id` int(11) NOT NULL, `foo_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 | +-------+------------------------------------------------------------- +--------------------------------------------------------------------- +----------+ 1 row in set (0.00 sec) mysql> show create table bar; +-------+------------------------------------------------------------- +--------------------------------------------------------------------- +--------------------------------------------------------------------- +--------------------------------------------+ | Table | Create Table + + + | +-------+------------------------------------------------------------- +--------------------------------------------------------------------- +--------------------------------------------------------------------- +--------------------------------------------+ | bar | CREATE TABLE `bar` ( `id` int(11) NOT NULL, `foo_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `foo_id_fk` (`foo_id`), CONSTRAINT `foo_id_fk` FOREIGN KEY (`foo_id`) REFERENCES `foo` (`id` +) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 | +-------+------------------------------------------------------------- +--------------------------------------------------------------------- +--------------------------------------------------------------------- +--------------------------------------------+ 1 row in set (0.00 sec) mysql> drop table foo; ERROR 1217 (23000): Cannot delete or update a parent row: a foreign ke +y constraint fails mysql> drop table bar; Query OK, 0 rows affected (0.00 sec) mysql> drop table foo; Query OK, 0 rows affected (0.00 sec)
As you can see, it looks like mysql silently ignores references in your SQL statements and doesn't create foreign keys. I would say it is rather nasty behaviour, if it doesn't accept your syntax it should throw an error.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: dbicdump and relationships
by blue_cowdawg (Monsignor) on Jan 14, 2013 at 15:13 UTC | |
by Anonymous Monk on Jan 14, 2013 at 15:18 UTC | |
|
Re^4: dbicdump and relationships
by blue_cowdawg (Monsignor) on Jan 14, 2013 at 15:46 UTC |