Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migration in Laravel

Tags:

mysql

laravel

I am getting an error while migrating my tables. the error says

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'json null, start_date date not null, end_date date not null, status enum('' at line 1 (SQL: create table modules (id int unsigned not null auto_increment primary key, title varchar(191) not null, description text not null, image blob null, resources json null, start_date date not null, end_date date not null, status enum('pending', 'start', 'completed') not null default 'pending', user_id int not null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

my table have following values:

public function up()
    {
        Schema::create('modules', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title');
            $table->text('description');
            $table->binary('image')->nullable();
            $table->json('resources')->nullable();
            $table->date('start_date');
            $table->date('end_date');
           $table->ENUM('status',['pending','start','completed'])->default('pending');
            $table->integer('user_id');
            $table->timestamps();
        });
    }

this is my model code:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

    class modules extends Model
    {
        protected $fillable = [
            'title', 'description','image','resources', 'start_date','end_date','status','user_id',
        ];
    }

can anyone have the solution for this??

like image 525
Sagar Basnet Avatar asked Jan 26 '26 11:01

Sagar Basnet


2 Answers

As of Laravel, the $table->json() method will try to create an actual JSON field in the database. However, the JSON field was not added to MySQL until MySQL 5.7.8.

Therefore, if you're using a version of MySQL previous to 5.7.8, you need to just create it as a text field

MariaDB new version supported JSON. (Alpha version. Not recommended by Maria to production server. Only testing.)

MariaDB 10.1 do not support JSON

like image 57
Ismoil Shifoev Avatar answered Jan 28 '26 03:01

Ismoil Shifoev


The earlier version of maria db does not support json field type, see the link, https://mariadb.com/resources/blog/json-with-mariadb-10-2/

Please verify your mariadb version.

like image 45
Vineesh Avatar answered Jan 28 '26 02:01

Vineesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!