沃梦达 / 编程问答 / php问题 / 正文

未定义的表:7 错误:关系“费用";不存在

Undefined table: 7 ERROR: relation quot;expensesquot; does not exist(未定义的表:7 错误:关系“费用;不存在)

本文介绍了未定义的表:7 错误:关系“费用";不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我会说西班牙语,所以我用西班牙语写了收入和支出的控制器和模型;而其余的都是英文的..我手动重命名和更改了路由、控制器、迁移甚至模型.当我运行 php artisan migrate:reset 这是我的错误.

Since i am a spanish speaker, i wrote the controllers and models of income and expense in spanish; while all the rest were on english.. I renamed and changed manually Routes, Controllers, Migrations and even Models. And when i run php artisan migrate:reset this is my error.

未定义表:7 错误:关系费用"不存在(SQL:更改表费用"删除列location_id")**

Undefined table: 7 ERROR: relation "expenses" does not exist (SQL: alter table "expenses" drop column "location_id")**

我使用 psgql 和 laravel 5.3

I use psgql and laravel 5.3

这是我的代码:

    <?php

    namespace App;

    use IlluminateDatabaseEloquentModel;

    class Expense extends Model
    {

        protected $fillable = ['id', 'description', 'quantity'];


        public function locations()
        {

            return $this->hasMany('AppLocation');

        }
        public function icons()
        {

            return $this->hasMany('AppIcon');
        }
        public function types()
        {

            return $this->hasMany('AppType');
        }
        public function stores()
        {

            return $this->hasMany('AppStore');
        }

    }

迁移:

    <?php

use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;

class CreateExpensesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('expenses', function (Blueprint $table) {
            $table->increments('id');
            $table->float('quantity');
            $table->string('description');
            $table->integer('location_id')->unsigned();
            $table->integer('icon_id')->unsigned();
            $table->integer('type_id')->unsigned();
            $table->integer('store_id')->unsigned();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('expenses');
    }
}

位置迁移:

<?php

use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;

class CreateLocationsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('locations', function (Blueprint $table) {
            $table->increments('id');
            $table->string('address');
            $table->float('lat');
            $table->float('long');
            $table->integer('store_id')->unsigned();
            $table->timestamps();

            $table->foreign('store_id')->references('id')->on('stores')->onDelete('cascade');
        });

        Schema::table('expenses', function (Blueprint $table) {
            $table->foreign('location_id')->references('id')->on('locations')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('expenses', function (Blueprint $table) {
            $table->dropColumn('location_id');
        });

        Schema::dropIfExists('locations');
    }
}

型号:

<?php

namespace App;

use IlluminateDatabaseEloquentModel;

class Location extends Model
{

    protected $fillable = ['id', 'address', 'lat', 'long'];


    public function expenses()
    {

        return $this->belongsTo('AppExpense');
    }

    public function stores()
    {

        return $this->hasOne('AppStore');
    }
}

希望你能帮助我.

推荐答案

当它说

relation "expenses" does not exist

通常发生在您的费用表必须在 migration:reset 回滚 CreateLocationsTable 之前被删除时.

It usually happens when your expenses table must have been dropped before migration:reset rolled back CreateLocationsTable.

检查迁移的执行顺序.

当您尝试重置时,现在要修复它,请打开您的数据库,手动删除所有表并再次执行 migrate.

As you were trying to reset, to fix it now, open your database, drop all tables manually and execute migrate again.

这篇关于未定义的表:7 错误:关系“费用";不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:未定义的表:7 错误:关系“费用";不存在

基础教程推荐