Undefined table: 7 ERROR: relation quot;expensesquot; does not exist(未定义的表: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 错误:关系“费用";不存在
				
        
 
            
        - PHP - if 语句中的倒序 2021-01-01
 - PHP foreach() 与数组中的数组? 2022-01-01
 - 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
 - 如何在 Symfony2 中正确使用 webSockets 2021-01-01
 - Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
 - 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
 - 覆盖 Magento 社区模块控制器的问题 2022-01-01
 - 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
 - Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
 - openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
 
