【问题标题】:i always getting error on migration , what can i do for this kind of error我总是在迁移时遇到错误,我该怎么办这种错误
【发布时间】:2017-10-13 05:33:46
【问题描述】:
 [Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table def
inition; there can be only one auto column and it must be defined as a key
(SQL: create table `students` (`id` int unsigned not null auto_increment pr
imary key, `student_id` int unsigned not null auto_increment primary key, `
stuent_name` varchar(50) not null, `student_email` varchar(50) not null, `s
tudent_username` varchar(50) not null, `student_phone` varchar(50) not null
, `student_photo` text not null, `student_sex` varchar(191) not null, `stud
ent_status` varchar(191) not null, `created_at` timestamp null, `updated_at
` timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)

我不知道发生了什么,这个问题是在我尝试迁移时发生的

【问题讨论】:

  • 发布您的架构定义
  • php 工匠迁移
  • 不是这样,在你的 `App\database\migrations` 中发布代码的架构定义
  • Schema::create('students', function (Blueprint $table) { $table->increments('id'); $table->increments('student_id'); $table-> string('student_name', 50); $table->string('student_email',50); $table->string('student_username',50); $table->string('student_phone',50); $table ->text('student_photo'); $table->string('student_sex'); $table->string('student_status'); $table->timestamps();

标签: php database laravel-5 migration


【解决方案1】:

您有两个 auto_increment 键 id 和 studuent_id。自增键只能设置一个。

【讨论】:

  • 如果我有 id 和另一个 student_id 在同一张桌子上,那我该怎么办??
  • @prakashpokhrel 我认为您可以删除列 ID,然后保留 student_id。或者您可以手动增加 id。
  • @prakashpokhrel 很高兴它有帮助
猜你喜欢
  • 1970-01-01
  • 2021-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-06
  • 2021-07-07
  • 1970-01-01
  • 2012-04-14
相关资源
最近更新 更多