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

Can not activate plugin, Foreign key constraint is incorrectly formed #91

Open
staeglis opened this issue May 5, 2023 · 3 comments
Open

Comments

@staeglis
Copy link

staeglis commented May 5, 2023

I have the same issue as described there:
#31 (comment)
#1

I've checked the tables adn tried the mentioned workarounds. All using innodb with utf8mb4. What else could cause the error?

Best,
Stefan

@staeglis
Copy link
Author

staeglis commented May 5, 2023

I was able to create the table with this SQL command:

CREATE TABLE matomo_loginoidc_provider ( user VARCHAR( 100 ) NOT NULL, provider_user VARCHAR( 255 ) NOT NULL, provider VARCHAR( 255 ) NOT NULL, date_connected TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY ( provider_user, provider ), UNIQUE KEY user_provider ( user, provider ), FOREIGN KEY ( user ) REFERENCES matomo_user ( login ) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

@HatBeardZero
Copy link

I was able to create the table with this SQL command:

CREATE TABLE matomo_loginoidc_provider ( user VARCHAR( 100 ) NOT NULL, provider_user VARCHAR( 255 ) NOT NULL, provider VARCHAR( 255 ) NOT NULL, date_connected TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY ( provider_user, provider ), UNIQUE KEY user_provider ( user, provider ), FOREIGN KEY ( user ) REFERENCES matomo_user ( login ) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

I am trying to get this going on mysql 8 and matomo 5.x, and i get this when i try to run that.

Referencing column 'user' and referenced column 'login' in foreign key constraint 'matomo_loginoidc_provider_ibfk_1' are incompatible.

any thoughts where i can look?

@nbaud
Copy link

nbaud commented Mar 21, 2024

For me the trick was to modify the charset very precisely to what it is in the database with utf8mb3_general_ci
Without that the above query would not work.

For instance, check your database with

SHOW FULL COLUMNS FROM piwik_user;
(in my case)
Then adapt your query according to what you see. It needs to match perfectly otherwise you will get that weird misleading error message.

This went fine and the plugin got activated after passing the following query:

MariaDB [matomo]> CREATE TABLE piwik_loginoidc_provider (
    ->     user VARCHAR(100) NOT NULL,
    ->     provider_user VARCHAR(255) NOT NULL,
    ->     provider VARCHAR(255) NOT NULL,
    ->     date_connected TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
    ->     PRIMARY KEY (provider_user, provider),
    ->     UNIQUE KEY user_provider (user, provider),
    ->     FOREIGN KEY (user) REFERENCES piwik_user (login) ON DELETE CASCADE
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants