我有一个mysql语句:
'SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";'
我想在 laravel 5.4 的迁移文件中运行它,但我不知道该怎么做?
以下是我的迁移文件的部分内容:
> public function up()
> {
> //
> Schema::create('users', function (Blueprint $table) {
>
> // SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"
> // todo
>
> $table->engine = 'InnoDB';
> $table->charset = 'utf8mb4';
> $table->collation = 'utf8mb4_unicode_ci';
>
> $table->int('id',11)->comment('ID');
> $table->string('name',50)->nullable()->comment('name');
> $table->string('phone',20);
> ...
谁能帮帮我?
最佳答案
You can use
DB::statement
试试下面
public function up()
{
Schema::create('users', function (Blueprint $table) {
DB::statement('SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";');
//run other migrations
}
}
关于php - 如何在laravel 5.4 的迁移文件中使用原始mysql 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42576146/