как исправить? запрос sql migration

Тема в разделе "Laravel", создана пользователем mixnet, 3 дек 2020.

  1. mixnet

    mixnet Новичок

    С нами с:
    11 авг 2018
    Сообщения:
    146
    Симпатии:
    7
    at D:\OpenServer\domains\local\vendor\laravel\framework\src\Illuminate\D
    atabase\Connection.php:671
    667| // If an exception occurs when attempting to run a query, we'll
    format the error
    668| // message to include the bindings with SQL, which will make th
    is exception a
    669| // lot more helpful to the developer instead of just the databa
    se's errors.
    670| catch (Exception $e) {
    > 671| throw new QueryException(
    672| $query, $this->prepareBindings($bindings), $e
    673| );
    674| }
    675|

    1 D:\OpenServer\domains\local\vendor\doctrine\dbal\lib\Doctrine\DBAL\D
    river\PDOConnection.php:72
    Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42000]: Syntax error or acce
    ss violation: 1101 BLOB, TEXT, GEOMETRY or JSON column 'keywords' can't have a d
    efault value")

    2 D:\OpenServer\domains\local\vendor\doctrine\dbal\lib\Doctrine\DBAL\D
    river\PDOConnection.php:67
    PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1101 BL
    OB, TEXT, GEOMETRY or JSON column 'keywords' can't have a default value")


    класс миграции

    PHP:
    <?php

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

    class 
    CreateBlogTables extends Migration
    {
        
    /**
         * Run the migrations.
         */
        
    public function up(): void
        
    {
            
    $tables = config('nova-blog.tables');

            
    Schema::create($tables['categories'], function (Blueprint $table) {
                
    $table->increments('id');
                
    $table->string('slug')->unique();
                
    $table->string('name');
                
    $table->timestamps();
            });

            
    Schema::create($tables['posts'], function (Blueprint $table) use ($tables) {
                
    $table->increments('id');
                
    $table->string('slug')->unique();
                
    $table->string('title');
                
    $table->jsonb('keywords')->nullable()->default('[]');
                
    $table->string('description')->nullable();
                
    $table->string('template');
                
    $table->text('annotation')->nullable();
                
    $table->text('content')->nullable();
                
    $table->foreignId('category_id')->constrained($tables['categories'])->onDelete('cascade');
                
    $table->foreignId('author_id')->constrained($tables['users'])->onDelete('cascade');
                
    $table->timestamps();
                
    $table->timestamp('published_at')->useCurrent();

                
    $table->index('category_id');
                
    $table->index('author_id');
                
    $table->index('published_at');
            });

            if (
    config('database.default') === 'pgsql') {
                
    DB::statement(sprintf('alter table %s add ts tsvector null', $tables['posts']));
                
    DB::statement(sprintf('create index %1$s_ts_index on %1$s using gin (ts)', $tables['posts']));
            }

            
    Schema::create($tables['tags'], function (Blueprint $table) {
                
    $table->increments('id');
                
    $table->string('slug')->unique();
                
    $table->string('name');
                
    $table->timestamps();
            });

            
    Schema::create($tables['post_tags'], function (Blueprint $table) use ($tables) {
                
    $table->foreignId('post_id')->constrained($tables['posts'])->onDelete('cascade');
                
    $table->foreignId('tag_id')->constrained($tables['tags'])->onDelete('cascade');

                
    $table->index('post_id');
                
    $table->index('tag_id');
            });

            
    Schema::create($tables['comments'], function (Blueprint $table) use ($tables) {
                
    $table->increments('id');
                
    $table->string('content', 4000);
                
    $table->foreignId('post_id')->constrained($tables['posts'])->onDelete('cascade');
                
    $table->foreignId('author_id')->constrained($tables['users'])->onDelete('cascade');
                
    $table->timestamps();

                
    $table->index('post_id');
                
    $table->index('author_id');
            });
        }

        
    /**
         * Reverse the migrations.
         */
        
    public function down(): void
        
    {
            
    $tables = config('nova-blog.tables');
            
    Schema::dropIfExists($tables['comments']);
            
    Schema::dropIfExists($tables['post_tags']);
            
    Schema::dropIfExists($tables['tags']);
            
    Schema::dropIfExists($tables['posts']);
            
    Schema::dropIfExists($tables['categories']);
        }
    }
    драйвер использую mysql
     
  2. mixnet

    mixnet Новичок

    С нами с:
    11 авг 2018
    Сообщения:
    146
    Симпатии:
    7
    ещё такая ошибка

    SQLSTATE[42000]: Syntax error or access violation: 1101 BLOB, TEXT, GEOMETRY o
    r JSON column 'keywords' can't have a default value (SQL: create table `blog_pos
    ts` (`id` int unsigned not null auto_increment primary key, `slug` varchar(255)
    not null, `title` varchar(255) not null, `keywords` json null default '[]', `des
    cription` varchar(255) null, `template` varchar(255) not null, `annotation` text
    null, `content` text null, `category_id` bigint unsigned not null, `author_id`
    bigint unsigned not null, `created_at` timestamp null, `updated_at` timestamp nu
    ll, `published_at` timestamp default CURRENT_TIMESTAMP not null) default charact
    er set utf8mb4 collate 'utf8mb4_unicode_ci')
     
  3. mixnet

    mixnet Новичок

    С нами с:
    11 авг 2018
    Сообщения:
    146
    Симпатии:
    7
    разобрался