PHP artisan迁移不创建新表

前端之家收集整理的这篇文章主要介绍了PHP artisan迁移不创建新表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是Laravel的新手,我正在关注Laravel Documentations以及一些教程视频.但是,我在我的本地CMD提示符中运行这个PHP artisan迁移代码,而不是在PHPmyadmin中创建数据库表.在stackoverflow中还有其他几个与此相关的类似主题,但没有解决我的问题.请不要标记此副本.

好吧,它是这样的.我运行这段代码

  1. PHP artisan make:migration create_student_table --create=student

并在迁移文件夹中创建新文件,如2016_04_08_061507_create_student_table.PHP

然后在该文件中我运行此代码

  1. use Illuminate\Database\Schema\Blueprint;
  2. use Illuminate\Database\Migrations\Migration;
  3.  
  4. class CreateStudentTable extends Migration
  5. {
  6. /**
  7. * Run the migrations.
  8. *
  9. * @return void
  10. */
  11. public function up()
  12. {
  13. Schema::create('student',function (Blueprint $table) {
  14. $table->increments('id');
  15. $table->timestamps();
  16. $table->string('name',20);
  17. $table->string('email',255);
  18. });
  19. }
  20.  
  21. /**
  22. * Reverse the migrations.
  23. *
  24. * @return void
  25. */
  26. public function down()
  27. {
  28. Schema::drop('student');
  29. }
  30. }

然后在cmd我运行PHP artisan migrate但它没有创建学生表.相反,它显示此消息

[PDOException] sqlSTATE[42S01]: Base table or view already exists:
1050 Table ‘users’ already exists

几天前我使用类似的方法创建了用户表.但是没有创建新的学生表.我在这里遗漏了什么?
提前致谢.

这意味着Laravel首先尝试运行users表迁移.如果您正在开发中并且不需要保留数据,则可以删除users表,然后运行PHP artisan migrate

猜你在找的PHP相关文章