Closed AmitSenjaliya closed 1 year ago
Hi @AmitSenjaliya, I've replied to your same question on Discord. Let's discuss the issue over on Discord, since the issue is almost certainly unique to your setup (and unlikely to be a bug in the plugin).
I'm getting the same problem. In my case, I'm upgrading a Craft 2 site that already has the plugin installed. Could you let me know what the fix was in Amit's case, please?
@tyssen We didn't figure out quite why the error occurred, but we did find a workaround...
vendor/doublesecretagency/craft-adwizard/src/migrations/m180925_000002_adWizard_portDetailsField.php
if (!$fieldsService->saveField($field, false)) {
@lindseydiloreto Sorry, for the slow reply. After that change, my error changes to:
Column not found: 1054 Unknown column 'field_adWizard_details' in 'field list' The SQL being executed was: UPDATE craft_content SET field_adWizard_details='', dateUpdated='2022-05-31 04:26:21' WHERE elementId='953'
In my case, in craft_content
I've got three fields named field_adWizard_details_xxxxxxxx
where xxxxxxxx
is a different string for each field.
Just following up on this one again.
And again.
Hi @tyssen, ping me on Craft Discord. I have a handful of follow-up questions, we can troubleshoot it together in real-time.
This is fixed, per our separate conversation on Discord. The issue wasn't really related to the original issue in this thread, other than the fact that they were both migration errors.
Today's bug will only effect people who are migrating directly from Craft 2.x up to Craft 3.7. If you are migrating to a version of Craft lower than 3.7, you probably will not run into this issue. I won't be backporting a fix, since this can be considered an edge case, and we are now focused on Craft 4.
To summarize, this is a result of Craft adding field column suffixes in Craft 3.7.
For reference, I had to make the following hacks to that same migration file...
Added to the _createNewField
method:
// Ensure column suffix exists
FieldHelper::ensureColumnSuffix($field);
// Store for transfer of field values
$this->_columnSuffix = $field->columnSuffix;
Added to the _copyFieldValues
method:
// Get the field column, with suffix
$fieldColumn = "field_adWizard_details_{$this->_columnSuffix}";
// Port data to new column
foreach ($ads as $row) {
$this->update(
'{{%content}}',
[$fieldColumn => $row['details']],
['elementId' => $row['id']]
);
}
And I just realized there is an alternate solution...
Just hit this myself for some Craft 2 upgrades on my way to Craft 4. I totally get wanting to focus on Craft 4, but it'd still be good to have the Craft 3 upgrade work (from the latest version of Craft 2 to the latest Craft 3 - onward to Craft 4).
It'd be super helpful just to have some more detail on the error:
throw new Exception('Ad Wizard migration error: Unable to create "Details" field ' . Json::encode($field->getErrors()) . ' .');
Which shows:
Exception: Ad Wizard migration error: Unable to create "Details" field {"handle":["Handle \"adWizard_details\" has already been taken."]} .
I'm not quite sure how the field has already been created, but maybe worth a check in the migration? Or at the very least, some feedback on the error in the exception.
Next, another error:
> update in {{%content}} ...Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_adWizard_details' in 'field list'
The SQL being executed was: UPDATE `craft_content` SET `field_adWizard_details`='Link to Crystal Blue Lagoon Luxury Villas, Muri Beach, Rarotonga', `dateUpdated`='2022-10-21 09:48:05' WHERE `elementId`='558'
This is because you assume the content column is named field_adWizard_details
which won't be the case due to the new field suffix setup.
I've created a PR for you https://github.com/doublesecretagency/craft-adwizard/pull/40 but I think you might've made it tricky for yourself to create a new version after 3.1.4 just for Craft 3 (we can't go to Craft 4 straight from Craft 2), but maybe up to you to handle how best to deal with a new version.
Very interesting... Thanks for the PR @engram-design! 👍
I'll take a look at the nuances, and figure out the best way to tag and release these changes.
This is fixed once and for all, thanks @engram-design! Sorry it took so long to get that merged. 🙏
Worth saying one more time, this only affects people migrating from Craft 2 to Craft 3.7. If you stopped at any versions of Craft in between, this change is moot.
For people following that update path, set your Craft version to ^3.7
...
"craftcms/cms": "^3.7",
And set your Ad Wizard version to either ^3.1
or 3.1.5
...
"doublesecretagency/craft-adwizard": "^3.1", // Relaxed
"doublesecretagency/craft-adwizard": "3.1.5", // Strict
Then run composer update
. As long as you are also loading Craft 3.7, both specifications will provide you with the exact same package.
Hope that helps. Thanks again to @engram-design for the pull request! 👏
I have installed Craft CMS 3.7.36 version and tried to install the plugin but the below error occurred.
Migration: doublesecretagency\adwizard\migrations\m180925_000002_adWizard_portDetailsField
Exception: Ad Wizard migration error: Unable to create "Details" field.