我创建这些表并在final中添加一个外键,但是执行时会看到这个错误:
[Illuminate \ Database \ QueryException] SQLSTATE [42S01]:基表或视图已经存在:1050表'despesas'已经存在(SQL:create table despesas
(id_despesa
int 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)默认字符集utf8 collat e utf8_unicode_ci)。
[PDOException] SQLSTATE [42S01]:基表或视图已存在:1050表'despesas'已存在。
码:
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');
});
删除数据库,再次创建和迁移它。迁移时出现异常,因此数据库中的迁移表不是最新的。