1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Laravel の migrate で increments() のカラムは、$fillable = ['id'] にして create() で指定しても無視される

Last updated at Posted at 2015-02-23
database/migrations/create_hoge_table.php
Schema::create('hoges', function(Blueprint $table)
{
    $table->increments('id');
    $table->string('name');
    $table->timestamps();
}
app/Hoge.php
class Hoge extends Model {
    protected $table = 'hoges';
    protected $fillable = ['id', 'name'];
}
database/seeder/DatabaseSeeder.php
Hoge::create([
    'id' => 0,
    'name' => 'hoge'
]);
php artisan migrate
php artisan db:seed

マイグレーションもシーダーも動くけど、作成されたレコードを見るとid=1になってる

1
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?