【发布时间】:2020-12-13 20:10:27
【问题描述】:
我使用命令 php artisan make:migration migration_name 和 php artisan make:model ModelName -mcr 在我的 Laravel 项目上创建了迁移。
当我运行php artisan migrate 时,输出为nothing to migrate。
我检查了我的数据库,只有 migration 表没有行,甚至来自 Laravel 的 user 表也没有创建。
此问题发生在我的笔记本电脑和 PC 上
这是我使用 XAMPP 运行 Laravel 的环境
- Laravel 7.24 和 Laravel 5.8.38
- Apache/2.4.39 (Win64)
- PHP 7.3.7
- MariaDB 10.3.16
- 作曲家 1.10.10
这是迁移代码
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
//File name = 2020_08_11_064146_create_category_table.php
//File Path = database/migrations
class CreateCategoryTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('category', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('category');
}
}
我已经尝试过这些,但没有运气:
- 运行
composer dump-autoload - 运行
php artisan migrate:reset-> 无需回滚 - 运行
php artisan migrate:fresh->成功删除所有表,成功创建迁移表,没有要迁移的东西 - 运行
php artisan migrate --path="/database/migrations/"-> 没有要迁移的东西 - 运行
php artisan migrate:status-> 未找到迁移 - 运行
php artisan migrate:install-> 迁移表创建成功,但没有解决问题
TLDR:
我真正做的是:
- 使用 composer 下载 Laravel
- 编辑
.env以使用用户root连接到数据库 - 使用
php artisan make:migration create_table_category创建迁移 - 运行
php artisan migrate - 结果 =
Migration table create successfully, nothing to migrate。数据库只有表migrations没有行
编辑
如果我用php artisan migrate --path="database/migrations/2020_08_11_064146_create_category_table.php"之类的文件名完全指定路径,则可以运行迁移
【问题讨论】:
-
你的迁移已经在那里了吗?
-
迁移表中有条目吗?
-
你没有重命名迁移类名和文件名吧?
-
@NaveedAli 是的,所有迁移文件都存在于目录
database/migration -
@diliphirapara 我的迁移没有数据,只创建表和它的列
标签: php laravel laravel-5.8 laravel-7