Reputation: 13
I create these tables and add one foreingkey in final, but executing watch this error:
[Illuminate\Database\QueryException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'despesas' already exists (SQL: create table despesas
(id_despesa
i
nt unsigned not null auto_increment primary key, categoria
int unsigned not null, descricao
varchar(255) not null, valor_previsto
int not null, valor_real
int not null, created_at
timestamp null, updated_at
timestamp null) default character set utf8 collat
e utf8_unicode_ci).
[PDOException] SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'despesas' already exists.
Code:
Schema::create('despesas', function (Blueprint $table) {
$table->increments('id_despesa');
$table->integer('categoria')->unsigned();
$table->string('descricao');
$table->Integer('valor_previsto');
$table->Integer('valor_real');
$table->timestamps();
});
Schema::create('categorias', function (Blueprint $table) {
$table->increments('id');
$table->string('nome');
$table->timestamps();
});
Schema::table('despesas', function (Blueprint $table) {
$table->foreign('categoria')->references('id')->on('categorias');
});
Upvotes: 0
Views: 80
Reputation: 833
Drop the database, create and migrate it again. You had an exception while migrating, hence migrations table in your database is not up to date.
Upvotes: 0