添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
文质彬彬的豆芽  ·  阿里达摩院获KDD ...·  7 月前    · 
严肃的面包  ·  Git 的Auto ...·  1 年前    · 
慷慨的高山  ·  android - Return a ...·  1 年前    · 

Laravel 5.4: Specified key was too long error

原因:从LV 5.4起数据库默认字符集为utf8mb4(包括了对 emojis 的支持)。如果使用的是 MySQL v5.7.7 或更高版本不需要做什么修改。

使用更早版本的MySQL数据库(包括MariaDB)的童鞋可以这样修改了,修改文件 /project/app/Providers/AppServiceProvider.php

use Illuminate\Support\Facades\Schema; // 注意要引入命名空间
 public function boot()
        Schema::defaultStringLength(191); // 针对 早期 mysql 数据迁移

再重新使用迁移命令:

php artisan migrate

SQLSTATE[42S01]: Base table or view already exists: 1050

迁移数据时表已存在,

解决办法:

删除已存在的表,然后重新迁移。

迁移结果如下:
Laravel Base table or view already exists

PDOException::(“SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for ‘published_at’”)

  • 修改方法一:vim config/database.php
'mysql' => [
     'driver' => 'mysql',
.... ...
     'prefix' => '', 
     'strict' => true, // 修改这里
     'engine' => null,
'mysql' => [
     'driver' => 'mysql',
.... ...
     'prefix' => '', 
     'strict' => false, // 修改这里
     'engine' => null,

设置可为空的时间戳:

$table->nullableTimestamps() 

设置默认时间戳

$table->timestamps('created_at');// 会生成created_at\updated_at字段

PDOException::(“SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘created_at’ in ‘field list’”)

此问题是由于 table 迁移时没有设置默认时间戳字段,但使用的是 factory 方法 生成 seed 数据,可以修改

public function up()
      Schema::create('posts', function (Blueprint $table) {
      $table->increments('id');
      $table->string('slug')->unique();
      $table->string('title');
      $table->text('content');
      $table->timestamps(); // 添加这行

重复make:migration

确切来说,这个也不算是坑,因为这个操作本身就是只需执行一次

但对于新手来说,可能无意间就重复执行多次,而 make:migration 时是不会报错的;
而在执行迁移时问题就来了:

解决办法就是删除或修改同一 table 的 schema 名称。
这里写图片描述

php artisan db:seed 表名变复数 单数

这可能和 Chinglish 有关,老外习惯把表名写为复数,所以干脆默认Model 对应的表名是这个英文单词的复数形式
因此,要在 model 里重写 $table 属性,如:

protected $table='student';
目录:Laravel 5.4: Specified key was too long errorSQLSTATE[42S01]: Base table or view already exists: 1050PDOException::(“SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default va...
安装laravel-admin,执行 php artisan admin:install出现 : Illuminate\Database\QueryException : SQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘users’ already exists (SQL: create table users (id bigint unsigned not null auto_increment primary
laravel migrate报错Class 'Doctrine\DBAL\Driver\PDOMySql\Driver' not found问题原因解决 laravel 执行 php artisan migrate 命令报错。 Symfony\Component\Debug\Exception\FatalThrowableError : Class ‘Doctrine\DBAL\Driver\PDOMySql\Driver’ not found 查看composer.json已经安装过
[Illuminate\Database\QueryException] SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre ady exists (SQL: create table `users` (`id` int unsigned not null auto_incr ement ...
SQLSTATE[42S02]模型查询之模型名和表名 SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘test.admins’ doesn’t exist (SQL: select * from admins) 解决方法 模型名为Admin对应的数据库中的表名必须为复数admins 如bus=>buses child=>children 如果表名为单数,那么必须在模型中添加以下代码在模型里面直接添加以下代码 prote
一.创建表 1.执行命令:sudo php artisan make:migration create_tableName_table 执行完后会在 migrations 文件夹下面生成一个文件 2.在 up 方法中添加或者修改你需要的字段 3.执行命令: php artisan migrate 打开Navicat查看,表已创建成功 .表里添加字段 1.执行命令:php artisan make:migration alter_表名_table --table=表名 2.在 up 方法中添加或者修
命令 说明 备注 php artisan make:resource ? 创建api返回格式化资源 >=5.4版本可用 php artisan make:rule ? 创建validate规则 >=5.4版本可用 php artisan make:exce...
Laravel: 5.5.* 在迁移中有重命名操作的时候,运行 php artisan migrate 会提示 Class 'Doctrine\DBAL\Driver\PDOMySql\Driver' not found的错误信息, 可通过composer 安装 doctrine/dbal 类库,然后运行 迁移就可以了 修改 表字段的 enum值时,使用DB::statement() ...
重点:this is incompatible with sql_mode=only_full_group_by 在数据库上运行是正常的,但是在laravel上就报错,所以 ,应该是框架配置问题 直接找配置文件 database.php 中将strict改为true, 'strict' => true, 'modes' => [ 'STRICT_ALL_TABLES', 'ERROR_FOR_DIVISION_BY_
TP框架关联模型报错 SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Attr_id' in 'where clause' 需要去你模型关联的模型,添加一个 Attr_id 字段
报这种错误一点是你的表不存在,注意上述写的表的名字是否存在,先确定你的表写的是否正确。如果你的代码里面写的就是你数据库表的名字,此时你应该去数据库配置下(config下的database.php)把表前缀清空。要注意表前缀的两个引号之间不能有空格,不然也会报错。如果你有表前缀,在后面就不用写这个表前缀了。 —————————————————————————————————————————————...