【发布时间】:2016-07-29 07:44:45
【问题描述】:
我是Laravel 的新手,我正在关注Laravel Documentations 以及一些教程视频。但是,我在我的本地 CMD prompt 中运行此 php artisan migrate 代码,它没有在 phpmyadmin 中创建 Database Table。 stackoverflow 中还有其他几个与此相关的类似主题,但没有一个能解决我的问题。请不要标记此重复项。
好的,事情是这样的。我运行这段代码
php artisan make:migration create_student_table --create=student
新文件在迁移文件夹中创建为2016_04_08_061507_create_student_table.php
然后在那个文件中我运行这个code
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateStudentTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('student', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->string('name', 20);
$table->string('email', 255);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('student');
}
}
然后在 cmd 我运行 php artisan migrate 但它没有创建 student 表。而是显示此消息
[PDOException] SQLSTATE[42S01]:基表或视图已存在: 1050 表“用户”已经存在
我几天前使用与上述类似的方法创建了users 表。但是没有创建新的student 表。我在这里错过了什么吗?
提前致谢。
【问题讨论】:
-
迁移就像您的项目数据库的时间线。 Laravel 检查已经运行了哪些迁移,只运行那些尚未运行的迁移。该时间线保存到
migrations表中。所以你的问题是你没有migrations表记录,但有users表。如果您只是在这里学习,我建议您删除数据库中的所有表,然后运行php artisan migrate。 -
hmm thnx 的信息,好的,删除所有表现在可以工作。如果我将来仍然存在同样的问题怎么办。?当我做真正的项目时。那里的解决方案是什么?
-
如果你不碰
migrationstable,你就不会坚持。 Laravel 会知道已经运行了哪些迁移,并且不会再次尝试执行它们。 -
使用标志 :fresh 将重写表
标签: php laravel laravel-artisan artisan-migrate