За последние 24 часа нас посетили 20699 программистов и 1110 роботов. Сейчас ищет 341 программист ...

как исправить? запрос 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:
    1. <?php
    2.  
    3. use Illuminate\Support\Facades\Schema;
    4. use Illuminate\Database\Schema\Blueprint;
    5. use Illuminate\Database\Migrations\Migration;
    6.  
    7. class CreateBlogTables extends Migration
    8. {
    9.     /**
    10.      * Run the migrations.
    11.      */
    12.     public function up(): void
    13.     {
    14.         $tables = config('nova-blog.tables');
    15.  
    16.         Schema::create($tables['categories'], function (Blueprint $table) {
    17.             $table->increments('id');
    18.             $table->string('slug')->unique();
    19.             $table->string('name');
    20.             $table->timestamps();
    21.         });
    22.  
    23.         Schema::create($tables['posts'], function (Blueprint $table) use ($tables) {
    24.             $table->increments('id');
    25.             $table->string('slug')->unique();
    26.             $table->string('title');
    27.             $table->jsonb('keywords')->nullable()->default('[]');
    28.             $table->string('description')->nullable();
    29.             $table->string('template');
    30.             $table->text('annotation')->nullable();
    31.             $table->text('content')->nullable();
    32.             $table->foreignId('category_id')->constrained($tables['categories'])->onDelete('cascade');
    33.             $table->foreignId('author_id')->constrained($tables['users'])->onDelete('cascade');
    34.             $table->timestamps();
    35.             $table->timestamp('published_at')->useCurrent();
    36.  
    37.             $table->index('category_id');
    38.             $table->index('author_id');
    39.             $table->index('published_at');
    40.         });
    41.  
    42.         if (config('database.default') === 'pgsql') {
    43.             DB::statement(sprintf('alter table %s add ts tsvector null', $tables['posts']));
    44.             DB::statement(sprintf('create index %1$s_ts_index on %1$s using gin (ts)', $tables['posts']));
    45.         }
    46.  
    47.         Schema::create($tables['tags'], function (Blueprint $table) {
    48.             $table->increments('id');
    49.             $table->string('slug')->unique();
    50.             $table->string('name');
    51.             $table->timestamps();
    52.         });
    53.  
    54.         Schema::create($tables['post_tags'], function (Blueprint $table) use ($tables) {
    55.             $table->foreignId('post_id')->constrained($tables['posts'])->onDelete('cascade');
    56.             $table->foreignId('tag_id')->constrained($tables['tags'])->onDelete('cascade');
    57.  
    58.             $table->index('post_id');
    59.             $table->index('tag_id');
    60.         });
    61.  
    62.         Schema::create($tables['comments'], function (Blueprint $table) use ($tables) {
    63.             $table->increments('id');
    64.             $table->string('content', 4000);
    65.             $table->foreignId('post_id')->constrained($tables['posts'])->onDelete('cascade');
    66.             $table->foreignId('author_id')->constrained($tables['users'])->onDelete('cascade');
    67.             $table->timestamps();
    68.  
    69.             $table->index('post_id');
    70.             $table->index('author_id');
    71.         });
    72.     }
    73.  
    74.     /**
    75.      * Reverse the migrations.
    76.      */
    77.     public function down(): void
    78.     {
    79.         $tables = config('nova-blog.tables');
    80.         Schema::dropIfExists($tables['comments']);
    81.         Schema::dropIfExists($tables['post_tags']);
    82.         Schema::dropIfExists($tables['tags']);
    83.         Schema::dropIfExists($tables['posts']);
    84.         Schema::dropIfExists($tables['categories']);
    85.     }
    86. }
    драйвер использую 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
    разобрался