【发布时间】:2018-05-07 09:01:27
【问题描述】:
我试图使用此处的代码在 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) {
//
});
}
}
产生的错误在这里:
C:\Users\think\Documents\NZ\blog>php artisan 迁移
Illuminate\Database\QueryException : SQLSTATE[08006] [7] 致命: 数据库“tripplan1”不存在(SQL:select * from information_schema.tables 其中 table_schema = public 和 table_name = 迁移) 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|捕获(异常 $e){664|抛出新的查询异常( 665| $query, $this->prepareBindings($bindings), $e 666| ); 667| }
C:\Users\think\Documents\NZ\blog>php artisan migrate 迁移表 创建成功。
Illuminate\Database\QueryException : SQLSTATE[42P01]: 未定义 表:7 错误:关系“城市”不存在(SQL:alter table “城市”添加列“id”序列主键不为空,添加列 “created_at”时间戳(0)没有时区空,添加列 “updated_at”时间戳(0)没有时区为空,添加列“名称” 文本不为空,添加列“信息” json 不为空,添加列 “country_id”整数不为空,添加列“lat”双精度不 null,添加列“lon”双精度不为空)在 C:\Users\think\Documents\NZ\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664 660| // 如果尝试运行查询时发生异常,我们将格式化错误 661| // 包含与 SQL 的绑定的消息,这将使该异常成为 662| // 对开发人员更有帮助,而不仅仅是数据库的错误。 663|捕获(异常 $e){
664|抛出新的查询异常( 665| $query, $this->prepareBindings($bindings), $e 666| ); 667| } 668|
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 查看更多详细信息。
任何帮助将不胜感激。
编辑:整个错误输入错误。数据库名称已更正...
【问题讨论】:
-
啊抱歉。那是一次错误。我删除了那个错误。但是错误地在这里发布了两个错误。现在已经纠正了错误。谢谢。
标签: laravel laravel-5 migration database-migration