Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I see that DBIx::Class::Schema::Loader::DBI::mysql uses SHOW CREATE TABLE to get table definition, and then looking for

CONSTRAINT ... FOREIGN KEY ... REFERENCES ...
to get information about foreign keys. I tried to create some tables in mysql and check the output of SHOW CREATE TABLES:
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.


In reply to Re^3: dbicdump and relationships by zwon
in thread dbicdump and relationships by blue_cowdawg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (5)
    As of 2014-12-28 08:26 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (179 votes), past polls