Why I am getting error for using jsonb keyword in Laravel? - laravel

I'm trying to learn Laravel Authorization using following mentioned tutorial:
Tutorial Link.
I'm using mysql database and default collation of the database is utf8mb4_unicode_ci. In Role's Database Migration permissions table data type was jsonb. That statement was:
$table->jsonb('permissions')->default('{}'); // you can check the tutorial link
After giving php artisan migrate --seed command, I am getting following error:
Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your S
QL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'json not null
default '{}', `created_at` timestamp null, `updated_at` timestamp ' at line 1 (SQL: create table `roles` (`id` int unsigned
not null auto_increment primary key, `name` varchar(191) not null, `slug` varchar(191) not null, `permissions` json not null
default '{}', `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unic
ode_ci')
I want to go through similarly like the mentioned tutorial but stuck here. How can I solve this?

Related

Spring Test H2 Flyway - error in sql statement

I have the following sql migration, that doesn't work with h2. If I remove the following SQL - everything works fine. How can i solve it?
SQL State : 42001
Error Code : 42001
Message : Syntax error in SQL statement "CREATE TABLE USER_AUTHORITY
(
USER_AUTHORITY_ID BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
USER_ID BIGINT REFERENCES USR (USER_ID) NOT NULL[*],
AUTHORITY_ID BIGINT REFERENCES AUTHORITY (AUTHORITY_ID) NOT NULL,
OPERATION VARCHAR(2) NOT NULL,
CREATION_DATETIME TIMESTAMP WITH TIME ZONE NOT NULL,
MODIFYING_DATETIME TIMESTAMP WITH TIME ZONE NOT NULL
)"; expected "DEFERRABLE";
Location : db/migration/V1__Schema.sql (/home/v/IdeaProjects/stocky/user-service/build/resources/main/db/migration/V1__Schema.sql)
Line : 29
Statement : create table user_authority
This is a bug of the parser. I filled a new issue about it:
https://github.com/h2database/h2database/issues/3413
You can specify NOT NULL before REFERENCES as a workaround.
USER_ID BIGINT NOT NULL REFERENCES USR (USER_ID),
AUTHORITY_ID BIGINT NOT NULL REFERENCES AUTHORITY (AUTHORITY_ID),

Error on SQLite migrations after upgrade Laravel 5.8 to 6.2

I need some help!
I have an API built in laravel 5.8, i am upgrading the platform to 6.2.
After all changes in configuration files and some scripts php, all my tests witch run the migrations on SQLite is broken.
The following error is displayed:
SQLSTATE[HY000]: General error: 1 no such collation sequence: utf8_general_ci (SQL: CREATE TABLE events (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, event VARCHAR(255) NOT NULL COLLATE BINARY, description CLOB DEFAULT NULL COLLATE BINARY, invitation CLOB DEFAULT NULL COLLATE BINARY, sale CLOB DEFAULT NULL COLLATE BINARY, information CLOB DEFAULT NULL COLLATE BINARY, city VARCHAR(255) NOT NULL COLLATE BINARY,
location VARCHAR(255) NOT NULL COLLATE BINARY, date_start DATE NOT NULL, time_start TIME NOT NULL, date_end DATE DEFAULT NULL, flyer CLOB DEFAULT NULL COLLATE BINARY, atv BOOLEAN DEFAULT '1', created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, location_map VARCHAR(255) DEFAULT NULL COLLATE utf8_general_ci --IFRAME com a localização do evento.
My intention is update to 7.x after resolve all issues on 6.2.
In the migrations, was enough to remove the collation option from the fields. Example:
Initially this way:
$table->string('field', 255)->charset('utf8')->collation('utf8_general_ci')->change();
The solution was as follows:
$table->string('field', 255)->charset('utf8')->change();
Removing this option will not force a collation not accepted by SQLite.

artisan migrate error 140 wrong create options

I've just moved from a Vagrant-based localhost setup to a Docker setup running :
PHP 7.2.8
PHP-FPM 7.2.8
Mariadb 10.2.15 (webhippie/mariadb)
I exec'ed into the Docker machine running FPM and did php artisan migrate, but was greeted with the following error :
SQLSTATE[HY000]: General error: 1005 Can't create table `data`.`migrations` (errno: 140 "Wrong create options") (SQL: create table `migrations` (`id` int unsigned not null auto_increment primary key, `migration` varchar(191) not null, `batch` int not null) default character set utf8mb4 collate utf8mb4_unicode_ci engine = InnoDB ROW_FORMAT=DYNAMIC)
I have another Laravel install running with the same Docker machines and no problem doing migrations.
From the erorr message, it seems there is an error during Laravel's creation of the migrations table. I've no idea what to do next. Help?
UPDATE :
Tried running the creation query :
create table `migrations` (`id` int unsigned not null auto_increment primary key, `migration` varchar(191) not null, `batch` int not null) default character set utf8mb4 collate utf8mb4_unicode_ci engine = InnoDB ROW_FORMAT=DYNAMIC
Removing option ROW_FORMAT=DYNAMIC successfully creates the migrations table. Will removing it impact Laravel's operation?
I think I got the answer.
I set engine = 'innodb ROW_FORMAT=DYNAMIC' at config/database.php. I did this a long time ago when trying to fix Laravel's key too long error. There is a simple fix (in the link) which limits string length to 191. so to fix the problem, just set engine = 'innodb' or engine = 'null' at config/databse.php.
check this out
https://laracasts.com/discuss/channels/eloquent/migrations-and-table-options-row-format?page=0
and let me know if it doesn't work
change config/database.php
'connections' => [
...
'mysql' => [
...
'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',
]
...

Missing fields in a joomla sql schema

I exported my joomla.sql file through phpMyAdmin and one of the sql statement below is not complete.
CREATE TABLE XXXX_postinstall_messages (
postinstall_message_id bigint(20) UNSIGNED NOT NULL,
extension_id bigint(20) NOT NULL DEFAULT '700' COMMENT 'FK to #__extensions',
title_key varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''COMMENT
) ;
Can someone assist to provide the full schema for this particular table?
here you'll find all joomla tables https://github.com/joomla/joomla-cms/blob/staging/installation/sql/mysql/joomla.sql

what's happened with my php artisan migrate

[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error i
n your SQL syntax; check the manual that corresponds to your MySQL server v
ersion for the right syntax to use near ') on delete cascade on update casc
ade' at line 1 (SQL: alter table users add constraint users_address_id_fo
reign foreign key (address_id) references address () on delete cascade
on update cascade)
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error i
n your SQL syntax; check the manual that corresponds to your MySQL server v
ersion for the right syntax to use near ') on delete cascade on update casc
ade' at line 1
migrate [--bench[="..."]] [--database[="..."]] [--force] [--path[="..."]] [--pac
kage[="..."]] [--pretend] [--seed]
public function up()
{
Schema::create('users',function($table){
$table->increments('id');
$table->string('name',30);
$table->string('phone',11);
$table->integer('age');
$table->string('email',50);
$table->string('marry_status',10);
$table->integer('address_id');
$table->foreign('address_id')->reference('id')->on('address')->onDelete('cascade')->onUpdate('cascade');
$table->integer('points_id');
$table->foreign('points_id')->reference('id')->on('address')->onDelete('cascade')->onUpdate('cascade');
$table->timestamps();
});
}
php migrate --pretend
CreateUsersTable: create table `users` (`id` int unsigned not null auto_increment primary key, `name` varchar(30) not null, `phone` varchar(11) not null, `age` int not null, `email` varchar(50) not null, `marry_status` varchar(10) not null, `address_id` int not null, `points_id` int not null, `created_at` timestamp default 0 not null, `updated_at` timestamp default 0 not null) default character set utf8 collate utf8_unicode_ci
CreateUsersTable: alter table `users` add constraint users_address_id_foreign foreign key (`address_id`) references `address` () on delete cascade on update cascade
CreateUsersTable: alter table `users` add constraint users_points_id_foreign foreign key (`points_id`) references `address` () on delete cascade on update cascade
CreateAddressTable: create table `address` (`id` int unsigned not null auto_increment primary key, `users_id` int not null, `name` varchar(30) not null, `created_at` timestamp default 0 not null, `updated_at` timestamp default 0 not null) default character set utf8 collate utf8_unicode_ci
CreatePointsTable: create table `points` (`id` int unsigned not null auto_increment primary key, `point` int not null, `users_id` int not null, `created_at` timestamp default 0 not null, `updated_at` timestamp default 0 not null) default character set utf8 collate utf8_unicode_ci
i try but i not good
public function up()
{
Schema::create('users',function($table){
$table->increments('id');
$table->string('name',30);
$table->string('phone',11);
$table->integer('age');
$table->string('email',50);
$table->string('marry_status',10);
$table->integer('address_id');
$table->integer('points_id');
$table->timestamps();
});
Schema::table('users',function($table){
$table->foreign('points_id')->references('id')->on('address')->onDelete('cascade')->onUpdate('cascade');
$table->foreign('address_id')->references('id')->on('address')->onDelete('cascade')->onUpdate('cascade');
});
}
You have error in your syntax. You are using reference() method, but the right method is references(). Fix it and I think everything will be ok.

Resources