Skip Menu |

This queue is for tickets about the DBIx-DataModel CPAN distribution.

Report information
The Basics
Id: 105680
Status: rejected
Priority: 0/
Queue: DBIx-DataModel

People
Owner: Nobody in particular
Requestors: aireland [...] lbl.gov
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Schema generator creates invalid schema if table has no primary key
Date: Sun, 5 Jul 2015 22:14:14 -0700
To: bug-DBIx-DataModel [...] rt.cpan.org
From: Amelia Ireland <aireland [...] lbl.gov>
DBIx::DataModel::Schema::Generator creates Table declarations in the form ->Table(qw/CatPhoto CAT_PHOTO photo_id/) If no primary key can be found, the last entry ('photo_id') is left blank, which triggers an error when the schema is then used. Possible solution: use the alternative form of table declaration: My::Schema->metadm->define_table( class => 'CatPhoto', db_name => 'CAT_PHOTO', primary_key => 'photo_id', # or omit if no PK can be found ); as the primary key can be safely omitted.
Subject: Re: [rt.cpan.org #105680] Schema generator creates invalid schema if table has no primary key
Date: Wed, 08 Jul 2015 09:16:56 +0200
To: bug-DBIx-DataModel [...] rt.cpan.org
From: Laurent Dami <laurent.dami [...] free.fr>
Le 06.07.2015 07:14, Amelia Ireland via RT a écrit : Show quoted text
> Mon Jul 06 01:14:53 2015: Request 105680 was acted upon. > Transaction: Ticket created by aireland@lbl.gov > Queue: DBIx-DataModel > Subject: Schema generator creates invalid schema if table has no primary key > Broken in: (no value) > Severity: (no value) > Owner: Nobody > Requestors: aireland@lbl.gov > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=105680 > > > > DBIx::DataModel::Schema::Generator creates Table declarations in the form > > ->Table(qw/CatPhoto CAT_PHOTO photo_id/) > > If no primary key can be found, the last entry ('photo_id') is left blank, > which triggers an error when the schema is then used. > > Possible solution: use the alternative form of table declaration: > > My::Schema->metadm->define_table( > class => 'CatPhoto', > db_name => 'CAT_PHOTO', > primary_key => 'photo_id', # or omit if no PK can be found > ); > > as the primary key can be safely omitted. >
Tables without primary keys are rather uncommon and have strong usage restrictions (can't perform joins, updates and deletes). So they should only be used willingly, not accidentally by an automatic schema generator. If the generator did not find the primary key, then probably the key was not declared as such within the database; better fix the problem at the root, or at least define it manually in the ORM as you did with 'photo_id'. The fact that the generated schema does not compile is a sign that there is a problem and that human intervention is needed; so I'm not in favour of a workaround that would hide the problem under the carpet.