Laravel returns Incorrect table Definition;

Asked

Viewed 68 times

0

When running migrate here, the Variable is returning:

Incorrect table Definition; there can be only one auto column and it must be defined as a key.

Attached is the code I’m using to create Migration:

 Schema::create('pessoas', function (Blueprint $table) {
            $table->increments('id');
            $table->string('nome',120);
            $table->string('tipopessoa',20);
            $table->string('nomefantasia',120)->nullable();
            $table->string('cpfcnpj',20)->nullable();
            $table->string('insc_est',25)->nullable();
            $table->string('insc_munic',25)->nullable();
            $table->date('datanasc')->nullable();
            $table->string('sexo',1)->nullable();
            $table->string('logradouro',100)->nullable();
            $table->string('numero_lograd',10)->nullable();
            $table->string('comple_lograd',80)->nullable();
            $table->string('bairro_lograd',40)->nullable();
            $table->integer('cod_munic')->nullable();
            $table->string('cep_lograd',10)->nullable();
            $table->string('fone',15)->nullable();
            $table->string('fax',15)->nullable();
            $table->string('email',50)->nullable();
            $table->string('site',50)->nullable();
            $table->integer('codusuacad')->nullable();
            $table->integer('celular',15)->nullable();
            $table->string('uf',10)->nullable();
            $table->integer('codusuaalt')->nullable();
            $table->string('insc_isento',50)->nullable();
            $table->string('logradouro_cor',100)->nullable();
            $table->string('comple_lograd_cor',80)->nullable();
            $table->string('bairro_lograd_cor',40)->nullable();
            $table->integer('cod_munic_cor')->nullable();
            $table->string('uf_cor',10)->nullable();
            $table->string('nome_pai',100)->nullable();
            $table->string('nome_mae',100)->nullable();
            $table->string('numero_pis',25)->nullable();
            $table->string('numero_ctps',25)->nullable();
            $table->string('cep_lograd_cor',10)->nullable();
            $table->string('endereco_cor',120)->nullable();
            $table->string('banco',60)->nullable();
            $table->string('agencia',40)->nullable();
            $table->string('conta',40)->nullable();
            $table->string('operacao',10)->nullable();
            $table->string('nacionalidade',60)->nullable();
            $table->string('naturalidade',60)->nullable();
            $table->string('necessidade_esp',60)->nullable();
            $table->string('deficiencia',60)->nullable();
            $table->date('emissao_rg')->nullable();
            $table->string('uf_rg',2)->nullable();
            $table->string('num_crc',20)->nullable();
            $table->date('emissao_crc')->nullable();
            $table->date('validade_crc')->nullable();
            $table->string('uf_crc')->nullable();
            $table->string('num_titulo')->nullable();
            $table->string('zona_titulo')->nullable();
            $table->string('secao_titulo')->nullable();
            $table->date('emissao_titulo')->nullable();
            $table->integer('municipio_id');
            $table->string('num_cnh')->nullable();
            $table->date('validade_cnh')->nullable();
            $table->date('primeira_cnh')->nullable();
            $table->string('uf_cnh')->nullable();
            $table->string('categoria_cnh')->nullable();
            $table->string('serie_ctps')->nullable();
            $table->string('uf_ctps')->nullable();
            $table->string('estado_civil')->nullable();
            $table->string('grau_instrucao')->nullable();
            $table->string('raca_cor')->nullable();
            $table->string('tipo_habitacao')->nullable();
            $table->integer('dependente')->nullable();
            $table->integer('nacionalidade_cod')->nullable();
            $table->integer('grau_instrucao_cod')->nullable();
            $table->integer('raca_cor_cod')->nullable();
            $table->integer('deficiencia_cod')->nullable();
            $table->integer('envportal')->nullable();
            $table->timestamps();
        });

1 answer

0


This is because the second parameter of "integer" columns is the $autoincrement flag and not the column size. Try changing

$table->integer('celular',15)->nullable();

for

$table->integer('celular')->nullable();

https://github.com/laravel/framework/blob/330d11ba8cd3d6c0a54a1125943526b126147b5f/src/Illuminate/Database/Schema/Blueprint.php#L443

In my opinion, a column that receives a phone number should be of the type character varying, for not being a foreign key, column of the type auto-increment and/or a index.

  • I forgot to put solved. But it was this msm. I use as varchar :D. I unintentionally put the integer. I’m learning to mess with Laravel.

  • Great, glad you could solve your problem. Good learning, hugs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.