マイグレーション ロールバックできない

初めてのLaravel 5.1 : (31) Relationships – ララ帳にて、



php artisan migrate:refresh

を実行しようとしても、

Fatal error: Class 'AddPublishedAtToArticlesTable' not found

とエラーが出てきてしまいます。



AddPublishedAtToArticlesTableクラスはあるんだけどなあ…




DBで

SHOW COLUMNS FROM articles;

すると

+------------+------------------+------+-----+---------+----------------+
| Field      | Type             | Null | Key | Default | Extra          |
+------------+------------------+------+-----+---------+----------------+
| id         | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| title      | varchar(255)     | NO   |     | NULL    |                |
| body       | text             | NO   |     | NULL    |                |
| created_at | timestamp        | YES  |     | NULL    |                |
| updated_at | timestamp        | YES  |     | NULL    |                |
+------------+------------------+------+-----+---------+----------------+

と、add_published_at_to_articles_table.phpで追加されているはずのpublished_atがないことがわかりました。



次に、

SELECT * FROM migrations;

で実行されているマイグレーションを見てみると、

+------------------------------------------------------+-------+
| migration                                            | batch |
+------------------------------------------------------+-------+
| 2014_10_12_000000_create_users_table                 |     1 |
| 2014_10_12_100000_create_password_resets_table       |     1 |
| 2016_03_27_154058_create_articles_table              |     1 |
| 2016_03_27_162924_create_articles_table              |     2 |
| 2016_03_27_164129_add_published_at_to_articles_table |     3 |
+------------------------------------------------------+-------+

add_published_at_to_articles_table.phpは実行されているみたい。

一旦、

delete from migrations where batch = 3;

で、 2016_03_27_164129_add_published_at_to_articles_tableを消してみました。



また、マイグレーションを実行してみると、

php artisan migrate

Migrated: 2016_03_28_165147_create_articles_table
Migrated: 2016_04_12_073227_add_published_at_to_articles_table

成功しました。



ロールバックしてみたら

php artisan migrate:refresh


[Illuminate\Database\QueryException]
  SQLSTATE[42S02]: Base table or view not found: 1051 Unknown table 'homestead.articles' (SQL: drop table `articles`)

  [PDOException]
  SQLSTATE[42S02]: Base table or view not found: 1051 Unknown table 'homestead.articles'




テーブルを確認してみると、

show tables;


+---------------------+
| Tables_in_homestead |
+---------------------+
| migrations          |
| password_resets     |
| users               |
+---------------------+

DBからarticlesテーブルなくなっているので、ロールバック成功!