2017-04-05 13 views
2

Laravelの移行を実行していないようです私は最近、「有給」の列を追加し、新たな移行を作成しました PHPUnitは</p> <p>をテストするために、私は、メモリのSQLiteデータベースに使用してい</p> <p>私はPHPUnitを経由laravel 5.4でいくつかのテストを実行している問題を持っている

<?php 

namespace Tests\Unit; 

use App\User; 
use App\Order; 
use Tests\TestCase; 
use Illuminate\Foundation\Testing\DatabaseMigrations; 
use Illuminate\Foundation\Testing\DatabaseTransactions; 

class OrderTest extends TestCase 
{ 
    use DatabaseMigrations; 

    /** @test */ 
    function can_update_status() 
    { 
     // This is empty, it fails on this test because its alphabetically the first test in the whole suite. 
    } 
} 

のように私はそれが効果的に見えるから、他の原料の束を削除したテストクラスを持っている

私はこのテストを実行するたび

は、しかし、私は有料の列が存在しないというエラーを取得する - でもcomposer du

PHPUnit 6.0.7 by Sebastian Bergmann and contributors. 

...................................E 

Time: 10.69 seconds, Memory: 46.00MB 

There was 1 error: 

1) Tests\Unit\OrderTest::can_mark_as_paid 
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such column: paid (SQL: update "orders" set "paid" = 1, "updated_at" = 2017-04-05 15:27:11 where "id" = 1) 

/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Connection.php:647 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Connection.php:607 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Connection.php:477 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Connection.php:416 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2145 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:768 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:581 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:501 
/Users/owen/Sites/1st-choice-spares/app/Order.php:62 
/Users/owen/Sites/1st-choice-spares/tests/Unit/OrderTest.php:95 

Caused by 
Doctrine\DBAL\Driver\PDOException: SQLSTATE[HY000]: General error: 1 no such column: paid 

/Users/owen/Sites/1st-choice-spares/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:79 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Connection.php:470 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Connection.php:640 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Connection.php:607 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Connection.php:477 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Connection.php:416 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2145 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:768 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:581 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:501 
/Users/owen/Sites/1st-choice-spares/app/Order.php:62 
/Users/owen/Sites/1st-choice-spares/tests/Unit/OrderTest.php:95 

Caused by 
PDOException: SQLSTATE[HY000]: General error: 1 no such column: paid 

/Users/owen/Sites/1st-choice-spares/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:77 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Connection.php:470 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Connection.php:640 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Connection.php:607 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Connection.php:477 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Connection.php:416 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2145 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:768 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:581 
/Users/owen/Sites/1st-choice-spares/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:501 
/Users/owen/Sites/1st-choice-spares/app/Order.php:62 
/Users/owen/Sites/1st-choice-spares/tests/Unit/OrderTest.php:95 

これが起こっだろう、と私は解決することができますどのように、なぜ誰もが任意のアイデアを持っていますそれ?私がダウンして、マイグレーションなど$table->dropColumn('paid');

の行をコメントアウトした場合、それは私が列名などを変更しようとしたと同じ問題がその

おかげ

UPDATE

で何が起こっている追加する価値があるかもしれません

それから実行を続けますが、アップが実行される前にダウンメソッドが実行される理由を理解するのに苦労していますか?

アップデート2

上記知見は、最初の場所で作成し得ていない列によるものであった私はそのエラーを抑制する場合は、元のエラーは、列が存在していないように見えるようだ - 移行を示唆していますそれを作成できませんでした。

+0

あなたは、このような各ステートメントを区切ることができますか? – Lorav

+0

BasketTestがアルファベット順に最初のものであり、実際のテストでは何もコメントしていないので、それはただ失敗します。そのため、マイグレーション後に文字通りそのようなことが起こったり、マイグレーションが実行されないこともあります。 – Owen

+0

Laravelのドキュメントでは、「SQLiteデータベースを使用している間に複数の列を1回のマイグレーションで削除または変更することはできません。多分それが理由でしょうか? – Lorav

答えて

1

ドロップ

laravelドキュメントに従って、またはサポートされていないSQLiteデータベースを使用しながら、単一のマイグレーション内で複数列を変更します。

そして、あなたは複数の列を変更またはドロップしようとしていないが、あなたは1つの移動中に落下し、作成しようとしていると、どちらの場合も、TABLEクエリをALTER実行され、ここでの問題は、limitations of ALTER TABLE query of sqliteです。私はユニット\ BasketTest \テストで失敗したテスト:: can_get_quotesは、あなたがこのテストを投稿することができますを参照してください

/** 
* Run the migrations. 
* 
* @return void 
*/ 
public function up() 
{ 
    Schema::table('orders', function (Blueprint $table) { 
     $table->dropColumn('completed'); 
    }); 

    Schema::table('orders', function (Blueprint $table) { 
     $table->boolean('paid')->default(0); 
    }); 
} 

/** 
* Reverse the migrations. 
* 
* @return void 
*/ 
public function down() 
{ 
    Schema::table('orders', function (Blueprint $table) { 
     $table->boolean('completed')->default(0); 
    }); 
    Schema::table('orders', function (Blueprint $table) { 
    $table->dropColumn('paid'); 
    }); 
} 
+0

これは論理的に意味がありますそれを試してみる - 私はupvoteしますが、確認するまで "答え"としてマークしません!しかし、提案に感謝:) – Owen

関連する問題

 関連する問題