Reputation: 43
I'm trying to insert a json string in to my Laravel 5.2 migration and I get an error, "Syntax error or access violation:1064".
I currently using MySQL version 5.6.17 as my database.
This is from my migration file:
Schema::create('profile', function (Blueprint $table) {
$table->increments('id');
$table->json('settings')->nullable();
$table->timestamps();
});
Can i somehow make this happen with my MySQL database or do i need to switch it up with MongoDB?
Upvotes: 4
Views: 1486
Reputation: 163748
You need to use MySQL 5.7.8 or higher to use json
columns.
You could update your MySQL version, or you could try to use text
as alternative. If it will not work as is, you could decode and encode your json data before and after using DB.
Upvotes: 2
Reputation: 62228
As of Laravel 5.2, 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 (which is how Laravel < 5.2 handles it).
Upvotes: 4