Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing set_primary_key() from schema files created by DBIx::Class::Schema::Loader #4

Open
hadjiprocopis opened this issue Nov 7, 2023 · 3 comments
Labels
bug Something isn't working question Further information is requested

Comments

@hadjiprocopis
Copy link

hadjiprocopis commented Nov 7, 2023

I am not sure if this issue is your responsibility or DBIx::Class's, but here it is:

I have changed DB from MySQL to MariaDB. I am also using DBIx::Class. So, I am using DBIx::Class::Storage::DBI::MariaDB you kindly provided in order to take care of the missing loader for MariaDB.

I have noticed that in the produced schema files with MySQL loader the primary key is set explicitly with this: __PACKAGE__->set_primary_key("id");. But with MariaDB loader the said declaration is missing and now I have:

__PACKAGE__->add_unique_constraint(
  "PRIMARY",

    [
      "id",
    ],
);

The above perhaps are equivalent but DBIx::Class complains with:

Error:  {UNKNOWN}: DBIx::Class::ResultSource::_pri_cols_or_die(): Operation requires a primary key to be declared on 'MyApp::Schema::XYZ' via set_primary_key ...

As if there is no primary key set.

This error disappears when I explicitly add a __PACKAGE__->set_primary_key("id"); in the custom-code section of the schema file.

EDIT after 30mins: Furthermore the primary key set via the constraint is not auto-incremented even if my SQL is something like:

CREATE TABLE IF NOT EXISTS XYZ (
        id mediumint unsigned NOT NULL primary key auto_increment,
        ...
) AUTO_INCREMENT=1;
@antoniskalou
Copy link
Contributor

Did you manage to figure out what was causing this?

I'm not sure this is related to DBIx::Class::Storage::DBI::MariaDB since we don't change anything regarding Schema::Loader. I think you'll need to look at https://metacpan.org/pod/DBIx::Class::Schema::Loader::DBI::mysql, you may need to port that to MariaDB.

Could you provide steps I can use to reproduce this issue? (E.g. a command line / code example)

@antoniskalou antoniskalou added bug Something isn't working question Further information is requested labels Jun 4, 2024
@hadjiprocopis
Copy link
Author

Some more clues in the question I posted over at Perlmonks.org : https://perlmonks.org/?node_id=11155430

From above thread, this (posted by rbrew) looks very promising:

https://blogs.perl.org/users/usna78/2024/05/mariadb-10-and-perl-dbixclassschemaloader.html

This is part of a much bigger program, I don't have a simple demo.

@hadjiprocopis
Copy link
Author

I can confirm that following the very detailed guide that "russbrewer" provided for us at (https://blogs.perl.org/users/usna78/2024/05/mariadb-10-and-perl-dbixclassschemaloader.html) my quite complex app works just fine with MariaDB and DBIx::Class with all the primary keys and auto-increment problems seemingly fixed. My tests are all passing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants