Skip to content

[5.x]: MySQL VIEW causes db/convert-charset command to fail #15598

@cweiper

Description

@cweiper

What happened?

Description

After updating our site with a custom plugin to Craft 5, running php craft db/convert-charset fails with the following error:

Converting view_name_here ... Error: SQLSTATE[HY000]: General error: 1347 'db.view_name_here' is not BASE TABLE

We are using a view to aggregate votes from a submissions table

Steps to reproduce

  1. Create site on Craft CMS 4
  2. Create custom plugin that creates a simple MySQL view inside a migration
  3. Upgrade to Craft CMS 5
  4. Remove the CRAFT_DB_CHARSET and CRAFT_DB_COLLATION settings
  5. Run php craft db/convert-charset

Example view creation code

// Create a view that shows the number of votes for each flavor and order by the number of votes
$this->execute('CREATE VIEW votes_by_choice AS
SELECT choiceId, SUM(numberOfVotes) AS numberOfVotes
FROM votes_submissions
GROUP BY choiceId
ORDER BY numberOfVotes DESC');

Expected behavior

Charset should be converted successfully

Actual behavior

Command fails with an error

Craft CMS version

5.3.6

PHP version

8.2

Operating system and version

DDEV

Database type and version

MySQL 8.0

Image driver and version

No response

Installed plugins and versions

  • Custom Voting Plugin
    "craftcms/ckeditor": "4.0.6",
    "craftcms/cms": "^5.0.0",
    "craftcms/shopify": "5.1.1",
    "nystudio107/craft-retour": "5.0.0",
    "nystudio107/craft-seomatic": "5.0.3",
    "putyourlightson/craft-blitz": "5.3.1",
    "verbb/formie": "3.0.3",

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions