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

[Craft 5] migration error upgrading from 5.0.2 => 5.1.0 #127

Closed
tomdavies opened this issue Dec 18, 2024 · 4 comments
Closed

[Craft 5] migration error upgrading from 5.0.2 => 5.1.0 #127

tomdavies opened this issue Dec 18, 2024 · 4 comments

Comments

@tomdavies
Copy link

I'm seeing the same issue reported in #124 and #125, but with the Craft 5 version of the plugin (Plugin version: 5.1.0, Craft version: 5.5.5):

One of Google Maps’s migrations failed.

Database Exception: SQLSTATE[HY000]: General error: 1832 Cannot change column 'siteId': used in a foreign key constraint 'fk_xxxxxxxxxxxxxxxxxxxxxxx'
The SQL being executed was: ALTER TABLE googlemaps_addresses CHANGE siteId siteId int(11) NOT NULL

Weirdly, the issue does not occur in every environment. The migrations ran fine in local dev (ddev) + internal QA, but breaks in client's environment. DB is MySQL 8.0.x in all three envs. I think main the difference might be whether devMode is true in the relevant environment or not.

Is a similar fix from 4.6.1 applicable to the Craft 5 branch, or not really?

I can provide a pre-migration DB snapshot + composer.json if needed.

Cheers!

@lindseydiloreto
Copy link
Collaborator

Thanks for reporting! Would you mind hacking the plugin to see if this fix will work?

Open this file:

/vendor/doublesecretagency/craft-googlemaps/src/migrations/m240530_122024_multisite_support.php

Replace the safeUp method with this:

public function safeUp(): bool
{
    // Add new columns
    $this->_newColumns();

    // Populate new columns with existing data
    $this->_populateData();

    // Make new column not nullable
    //  - AFTER the column has been populated
    //  - BEFORE adding indexes and foreign keys
    $this->alterColumn(Install::GM_ADDRESSES, 'siteId', $this->integer()->notNull());

    // Add new column indexes
    $this->_newIndexes();

    // Add new foreign keys
    $this->_newForeignKeys();

    // Post an announcement
    $this->_announcement();

    // Success
    return true;
}

If that works, let me know and I can release an official patch for it! 👍

@tomdavies
Copy link
Author

Thanks @lindseydiloreto - will report back 🫡

@tomdavies
Copy link
Author

Confirmed that the ☝️ change resolved the issue we were having on 5.1.0 upgrade. A release would be great when you can, but appreciate we are close to the holidays, and our individual issue is resolved by using a temp fork with your change for now

@lindseydiloreto
Copy link
Collaborator

Hope you had a great holiday season, thanks for your patience @tomdavies!

This patch has been officially released in v5.1.1.

And thanks again for reporting it! 🍺

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

2 participants