I'm creating a system and I have two columns: empresas
and usuarios
. The usuarios.id_empresa
does is the foreign key of empresas.id_empresa
, however, some data of the two tables are filled in simultaneously and after the registration is done the other information can be inserted. However, if I run php artisan migrate
without having data in the empresas
table it appears the error that can not make that connection between the tables precisely because empresas
does not yet have data. How to solve this?
The log furmulary will have the inputs (between relatives on which table it belongs)
Name (users) Company (companies) Phone (companies) E-mail (companies) password (users)
Notice that this form will populate two tables at the same time, so I need to reference usuarios.id_empresas
in empresas.id_empresa
.
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('user_id');
$table->integer('user_empresa')->unsigned();
$table->string('user_nome');
$table->string('user_email')->unique();
$table->string('user_cpf')->unique()->nullable();
$table->string('user_rg')->unique()->nullable();
$table->string('user_telefone')->nullable();
$table->string('user_senha');
$table->boolean('user_ativo');
$table->string('user_permissions');
$table->integer('user_profile')->unsigned();
$table->timestamps();
/* $table->foreign('user_empresa')
->references('empresa_id')
->on('empresas')->onDelete('cascade');*/
});
}
public function up()
{
Schema::create('empresas', function (Blueprint $table) {
$table->increments('empresa_id');
$table->string('empresa_nome');
$table->string('empresa_email')->unique();
$table->string('empresa_cnpj_cpf')->nullable();
$table->string('empresa_telefone');
$table->boolean('empresa_trial')->default(1);
$table->boolean('empresa_ativo')->default(0);
$table->boolean('empresa_cad_completo')->default(0);
$table->string('empresa_plano')->default(0);
$table->date('empresa_expira');
$table->timestamps();
});
}