我是 laravel 的新手。我使用迁移创建表“users”。但是当我想使用不同的迁移创建第二个“timelog”时,它会给出错误消息“找不到表”。然后我也删除所有迁移表和数据库表。我再次尝试使用迁移创建表“用户”。但是 laravel 在终端中给出错误消息。错误消息如下:
[照亮\数据库\QueryException]
SQLSTATE[42S02]:未找到基表或 View :1146 表“hrm.users”不存在(SQL:alter table users
add id
int u
nsigned not null auto_increment主键,添加username
varchar(255) 不为空,添加 email
varchar(255) 不为空,添加 c<br/>
ontactnumber
varchar(255) 不为空,添加 password
varchar(255) 不为空,添加 created_at
时间戳默认 0 不为空,广告
d updated_at
时间戳默认0不为空)
[PDO异常]
SQLSTATE[42S02]:未找到基表或 View :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/