4
Good morning, I am running some tests on my application, but I have the following problem: After the migrate and the db:seed, whenever I will enter some record by applying a duplicated primary key error. I have seen that this error is due to the increment continue to 1 even after entering data with db:seed. Would there be some way for me to set this value manually automatically, without having to go from table to table and changing?
Seed:
 public function run()
    {
        Model::unguard();
        App\Models\Admin\Profissao::create(['id'                       => '1', 
            'titulo'                => 'Engenheiro(a)',
        ]);
        App\Models\Admin\Profissao::create(['id'                       => '2', 
            'titulo'                => 'Tecnólogo(a)',
        ]);
        Model::reguard();
    }
Migration:
public function up()
{
    Schema::create('profissoes', function (Blueprint $table) {
        $table->engine = 'InnoDB';
        $table->increments('id');
        $table->string('titulo', 16);
        $table->longText('descricao')->nullable();
        $table->timestamps();
    });
}
						
ideal is you leave the table blank and perform the Seed, already tried it?
– RFL
Post your Seed and your Migration. Are you setting the column in the database to Serial? Your Seed is setting values for the ID column manually?
– Marco Aurélio Deleu
What do you mean? What I do is I run migrate to create the tables, so it’s all going to be blank, right? And then I run Seed, but Seed doesn’t change the increment there in the sequences.
– Raylan Soares
Posted @Marcoauréliodeleu
– Raylan Soares
Remove the id column specification from your seeder and make sure the problem goes away. That is, just put the title column in the seeder.
– Marco Aurélio Deleu
Okay, I’ll see here.
– Raylan Soares
That’s right @Marcoauréliodeleu. I didn’t really think it could be this... Thank you so much!
– Raylan Soares