[英]SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; change column
goal: change the column meta-settings in table settings.目标:更改表设置中的列元设置。
I'm trying to change a column name in a table I created before, so I followed the steps:我正在尝试更改之前创建的表中的列名,因此我按照以下步骤操作:
composer require doctrine/dbal
php artisan make:migration update_oldFileName_table
update_oldNameFile_table.php
Schema::table('settings', function (Blueprint $table) {
$table->renameColumn('meta-description', 'metaDescription');
});
php artisan migrate
However, it shows me this error:但是,它向我显示了这个错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;
SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-description metaDescription VARCHAR(255) NOT NULL' at line 1 (SQL: ALTER TABLE settings CHANGE meta-description metaDescription VARCHAR(255) NOT NULL)
检查与您的 MariaDB 服务器版本相对应的手册,以在第 1 行的“-description metaDescription VARCHAR(255) NOT NULL”附近使用正确的语法(SQL:ALTER TABLE settings CHANGE meta-description metaDescription VARCHAR(255) NOT NULL)
I think the problem is because the - in "meta-description" but I want to change it!我认为问题是因为 - 在“元描述”中,但我想改变它!
you can add backticks around the column name:您可以在列名周围添加反引号:
$table->renameColumn('`meta-description`', 'metaDescription');
the problem is that - is an operator.问题是 - 是一个运算符。 the backticks make sure that is ignored.
反引号确保被忽略。
You need doctrine/dbal
package in order to perform this action.您需要
doctrine/dbal
package 才能执行此操作。
composer require doctrine/dbal
Run your migration again, and the error should go away.再次运行迁移,错误应该 go 消失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.