Laravel Migration Returning Invalid SQL

左心房为你撑大大i 提交于 2020-01-16 07:59:09

问题


I am running Laravel 6.0.2 and my migration up method is as follows:

Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('first_name');
            $table->string('last_name');
            $table->string('email')->unique();
            $table->string('password');
            $table->boolean('admin')->default(false);
            $table->boolean('manager')->default(false);
            $table->rememberToken();
            $table->timestamps();
});
create table `users` (
  `id` int unsigned not null auto_increment primary key,
  `first_name` varchar(255) not null,
  `last_name` varchar(255) not null,
  `email` varchar(255) not null,
  `password` varchar(255) not null,
  `admin` tinyint(1) not null default ('0'),
  `manager` tinyint(1) not null default ('0'),
  `remember_token` varchar(100) null,
  `created_at` timestamp null,
  `updated_at` timestamp null
) default character set utf8mb4 collate 'utf8mb4_unicode_ci'

I have run that SQL on an online syntax checker and that is giving me and error on the admin tinyint(1) not null default ('0'), line.

I am not sure whether this is a Laravel 6.0.2 bug as it seemed to be working before that update.

Has anyone run into this issue and know of the fix?


回答1:


Well, this is pretty easy to fix and pretty easy to overlook. My guess is you've been looking at it for too long.

Your DEFAULTs don't need parenthesis or the quotes. The quotes are only there for strings, not ints, and the parens are only needed if it's a subquery (which isn't likely would actually work, but I haven't tried it).

http://www.w3webtutorial.com/mysql/mysql-default-constraint.php




回答2:


In mysql boolean type is tinyint 0 false 1 true ...


$table->boolean('admin')->default(0);



来源:https://stackoverflow.com/questions/57876574/laravel-migration-returning-invalid-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!