我是laravel的新手。我使用迁移创建表“用户”。但是当我想使用不同的迁移创建第二个“时间日志”时,它会显示错误消息“找不到表”。然后,我还要删除所有迁移表和数据库表。我再次尝试使用迁移创建表“ users”。但是laravel在终端中给出了错误消息。错误消息如下:
 [Illuminate \ Database \ QueryException]
  SQLSTATE [42S02]:找不到基表或视图:1146表'hrm.users'不存在(SQL:alter table users add id int u
  nsigned不为null auto_increment主键,添加username varchar(255)不为空,添加email varchar(255)不为空,添加c
ontactnumber
varchar(255)不为空,添加password varchar(255)不为空,添加created_at时间戳默认为0,不为null,广告
  d updated_at时间戳默认为0,不为null)

[PDOException]
  SQLSTATE [42S02]:找不到基表或视图:1146表'hrm.users'不存在

我怎么解决这个问题。

最佳答案

检查您的app / database / migrations文件夹,如果您要迁移,Laravel将创建其中列出的所有表,这些表尚未包含在迁移表中。

sql查询建议您尝试更改(而不是创建)表,因此请查看迁移类,并确保它们看起来像这样:

    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Database\Migrations\Migration;

    class CreateSomething extends Migration {

        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            Schema::create('something', function($table) {
                $table->increments('id');
                ...
            });
        }

        /**
         * Reverse the migrations.
         *
         * @return void
         */
        public function down()
        {
            //drop the table
        }

    }

关于mysql - 在Laravel中使用迁移创建表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26968161/

10-11 05:36
查看更多