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.