2016-11-30 27 views
1

私はスペイン語のスピーカーなので、私はスペイン語で収入と費用のコントローラとモデルを書いています。残りはすべて英語で書かれていました。 ルート、コントローラ、マイグレーション、さらにはモデルの名前を変更して手動で変更しました。 そして、私がphp artisan migrateを実行するとき:これは私のエラーです。未定義のテーブル:7エラー:relation "expenses"が存在しません

<?php 

    namespace App; 

    use Illuminate\Database\Eloquent\Model; 

    class Expense extends Model 
    { 

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


     public function locations() 
     { 

      return $this->hasMany('App\Location'); 

     } 
     public function icons() 
     { 

      return $this->hasMany('App\Icon'); 
     } 
     public function types() 
     { 

      return $this->hasMany('App\Type'); 
     } 
     public function stores() 
     { 

      return $this->hasMany('App\Store'); 
     } 

    } 

移行:

<?php 

use Illuminate\Support\Facades\Schema; 
use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

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'); 
    } 
} 

場所MIGRAT私はこれが私のコードでpsgqlとlaravel 5.3

を使用

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

イオン:

<?php 

use Illuminate\Support\Facades\Schema; 
use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

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 Illuminate\Database\Eloquent\Model; 

class Location extends Model 
{ 

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


    public function expenses() 
    { 

     return $this->belongsTo('App\Expense'); 
    } 

    public function stores() 
    { 

     return $this->hasOne('App\Store'); 
    } 
} 

はあなたが私を助けることができると思います。

+0

あなたは何を理解していませんか? –

+0

psgqlに移行しようとするとこれらのエラーが発生します。 –

+0

エラーメッセージは非常に明確です - 費用表という名前はありません。 –

答えて

0

それは通常migration:resetバックCreateLocationsTableロールの前にあなたの費用表がドロップされていなければならない場合に発生

relation "expenses" does not exist 

を言います。

移行の実行順序を確認してください。

リセットしようとしていたので、今すぐ修正してデータベースを開き、すべてのテーブルを手動で削除してからmigrateを再度実行してください。

+0

ありがとう、これは本当に助けになりました! –

関連する問題