Nis*_*Sah 2 migration database-migration laravel laravel-5
我试图使用此处的代码在 laravel 中创建迁移。但不幸的是,它弹出了一个像这里给出的错误。我看到了一些我手动创建表的答案.. 但这与迁移的整个想法大相径庭.. 不是吗?
迁移文件 2018_05_05_203731_create_cities_table 在这里:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCitiesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('cities', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->text('Name');
$table->json('info');
$table->integer('country_id');
$table->float('lat');
$table->float('lon');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('cities', function (Blueprint $table) {
//
});
}
}
Run Code Online (Sandbox Code Playgroud)
产生的错误在这里:
C:\Users\think\Documents\NZ\blog>php artisan migrate
Illuminate\Database\QueryException : SQLSTATE[08006] [7] 致命:数据库“tripplan1”不存在(SQL:select * from information_schema.tables where table_schema = public and table_name = migrations)es不存在”)在 C:\Users \think\Documents\NZ\blog\vendor\laravel\framework\src\Illuminate\Databasee\Connection.php:458\Connection.php:664 660| // 如果尝试运行查询时发生异常,我们将格式化错误
e\Connection.php:458 661| // 消息以包含与 SQL 的绑定,这将使此异常成为 662| // 对开发人员更有帮助,而不仅仅是数据库错误。663| catch (Exception $e) {664| throw new QueryException(665| $query, $this->prepareBindings($bindings), $e 666|); 667| }
C:\Users\think\Documents\NZ\blog>php artisan migrate 迁移表创建成功。
Illuminate\Database\QueryException:SQLSTATE[42P01]:未定义表:7 错误:关系“城市”不存在(SQL:改变表“城市”添加列“id”序列主键不为空,添加列“created_at”时间戳( 0) 无时区空,添加列“updated_at”时间戳(0) 无时区空,添加列“名称”文本非空,添加列“信息”json 非空,添加列“country_id”整数非空,添加列“lat”双精度非空,添加列“lon”双精度非空)在 C:\Users\think\Documents\NZ\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664 660 | // 如果在尝试运行查询时发生异常,我们' 我会格式化错误 661| // 包含与 SQL 的绑定的消息,这将使此异常成为 662| // 对开发人员更有帮助,而不仅仅是数据库的错误。663| 捕获(异常 $e){
664| throw new QueryException(665| $query, $this->prepareBindings($bindings), $e 666|); 667| 第668话
Run Code Online (Sandbox Code Playgroud)Exception trace:1 PDOException::("SQLSTATE[42P01]: 未定义表:7 错误:关系“城市”不存在") C:\Users\think\Documents\NZ\blog\vendor\laravel\framework\src\Illuminate\Database \Connection.php:458 2 PDOStatement::execute() C:\Users\think\Documents\NZ\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458
请使用参数 -v 查看更多详细信息。
任何帮助将不胜感激。
编辑:整个错误输入错误。数据库名称已更正...
| 归档时间: |
|
| 查看次数: |
2517 次 |
| 最近记录: |