【问题标题】:While Migrating database it shows error Syntax error or access violation: 1067 Invalid default value for 'domain_status'迁移数据库时显示错误语法错误或访问冲突:1067 'domain_status' 的默认值无效
【发布时间】:2020-12-14 06:42:19
【问题描述】:

我不知道如何解决这个问题

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateDomainsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return voidzz
     */
    public function up()
    {
        Schema::create('domains', function (Blueprint $table) {
            $table->id();
            $table->integer('user_id')->nullable();
            $table->string('domain')->collate('utf8_bin')->nullable();
            $table->string('google_domain')->collate('utf8_bin')->nullable();
            $table->string('location')->collate('utf8_bin')->nullable();
            $table->string('device')->collate('utf8_bin')->nullable();
            // $table->string('Hl')->nullable();
            // $table->string('Gl')->nullable();
            $table->string('hl')->collate('utf8_bin')->nullable();
            $table->string('gl')->collate('utf8_bin')->nullable();
            $table->integer('domain_status')->default('active')->nullable();
            $table->integer('update_frequency')->nullable();
            $table->timestampsTz();
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('domains');
    }
}

【问题讨论】:

  • 请分享create_domains_table迁移代码

标签: database laravel migration database-migration laravel-7


【解决方案1】:

您将domain_status 定义为int 列,但默认为名为@9​​87654323@ 的字符串。那是行不通的。

【讨论】:

  • 我应该在这里定义什么字符串?
  • 如果是integer,您可以使用->default(0)
  • @AnvitaRastogi:你应该定义你的程序期望什么。实际上,您必须知道该列想要什么 - 字符串或数字。
猜你喜欢
  • 2018-02-06
  • 2021-04-15
  • 2021-07-21
  • 1970-01-01
  • 2019-07-15
  • 2023-02-10
  • 2018-06-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多