laravel中数据库迁移的使用:
创建数据库迁移文件:
php artisan make:migration create_links_table
创建完表之后,设置字段:
public function up()
{
Schema::create('links', function (Blueprint $table) {
$table->engine="MyISAM";
$table->increments('links_id');
$table->string("links_name")->default("")->comment("友情链接的名字");
$table->string("links_title")->default("")->comment("友情链接的标题");
$table->string("links_url")->default("")->comment("友情链接的url");
$table->integer("link_order")->default(0)->comment("友情链接排序");
});
} public function down()
{
Schema::dropIfExists('links');
}
设置完字段之后,在运行数据库迁移文件:
php artisan migrate
为创建的数据库迁移文件创建的表填充数据:
创建数据填充文件:
php artisan make:seeder LinksTableSeeder
在文件中填充数据:
public function run()
{
//
$data=[
[
'links_name'=>"百度",
'links_title'=>"百度一下就知道",
'links_url'=>"https://www.baidu.com",
'links_order'=>1,
],
[
'links_name'=>"新浪",
'links_title'=>"新浪知天下",
'links_url'=>"https://www.sina.com",
'links_order'=>2,
]
];
DB::table('links')->insert($data);
}
在DtabaseSeeder中填写:
public function run()
{
$this->call(LinksTableSeeder::class);
}
运行:
php artisan db:seed
laravel中数据库迁移的使用:的更多相关文章
- 转: Laravel的数据库迁移 介绍的比较清晰
原文: https://blog.sbot.io/articles/12/Laravel-数据库迁移(Database-Migrations)操作实例 很多人可能在学习Laravel框架的时候,对La ...
- laravel执行数据库迁移的过程中出现Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] Operation timed out (SQL: select * from information_schema.tables where table_schema = shop and table_name = migrations
向customers表添加字段phone php artisan make:migration add_phone_to_customers_table 问题: 解决方法: 将DB_HOST配置项修改 ...
- Flask项目中数据库迁移的使用
数据库迁移 在开发过程中,需要修改数据库模型,而且还要在修改之后更新数据库.最直接的方式就是删除旧表,但这样会丢失数据. 更好的解决办法是使用数据库迁移框架,它可以追踪数据库模式的变化,然后把变动应用 ...
- laravel 中数据库查询结果自动转数组
今天在项目中再次碰见laravel中从数据库中查询到的结果是对象,用toArray也不好用,之前改过一次,印象中是在/confing/database.php, 'fetch' => PD ...
- Laravel进行数据库迁移(migration)
迁移(migration) 文档的简介是:迁移就像数据库的版本控制,允许团队简单轻松的编辑并共享应用的数据库表结构,迁移通常和 Laravel 的结构构建器结对从而可以很容易地构建应用的数据库表结构. ...
- laravel中数据库在哪个文件中配置
我们使用 mysql 数据库,修改 .env: DB_HOST=localhost DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD= 在mysql中创 ...
- Laravel 5 数据库迁移文件示例
php artisan make:migration create_stocks_table 在项目根目录执行上面的命令后,会在database/migrations目录下生成2016_06_03_1 ...
- Laravel数据库迁移
Laravel的数据迁移功能很好用,并且可以带来一系列好处.通过几条简单的 artisan 命令,就可以顺利上手,没有复杂的地方 注意:该系列命令对数据库非常危险,请准备一个单独的数据库作为配套练习, ...
- Laravel 5.2 数据库迁移和数据填充
一.数据库迁移 Laravel 的数据库迁移提供了对数据库.表.字段.索引的一系列相关操作.下面以创建友情链接表为例. 1. 创建迁移 使用 Artisan 命令 php artisan make: ...
随机推荐
- CSLA.Net学习(2)
采用CSLA.net 2.1.4.0版本的书写方式: using System; using System.ComponentModel; using Csla.Validation; using S ...
- Kconfig文件说明
Kconfig的格式 下面截取/drivers/net下的Kconfig文件中的部分内容: # Network device configuration menuconfig NETDEVICES d ...
- PAT 1109 Group Photo[仿真][难]
1109 Group Photo(25 分) Formation is very important when taking a group photo. Given the rules of for ...
- 20165324_mybash
20165324_mybash 实验要求 实验要求: 使用fork,exec,wait实现mybash 写出伪代码,产品代码和测试代码 发表知识理解,实现过程和问题解决的博客(包含代码托管链接) 背景 ...
- 跨域nginx,CORS
浏览器的同源策略是浏览器上为安全性考虑实施的非常重要的安全策略.从一个域上加载的脚本不允许访问另外一个域的文档属性.举个例子:比如一个恶意网站的页面通过iframe嵌入了银行的登录页面(二者不同源), ...
- 11. Container With Most Water(装最多的水 双指针)
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- .net webform 把word转为html
首先添加引用 引用命名空间 using Microsoft.Office.Interop.Word; using System; using System.Collections.Generic; u ...
- C# 解析soap数据为json格式
数据格式: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soa ...
- android驱动学习---led实验
======================== 驱动: 内核:android-kernel 2.6.36 (必须对应你的板子上内核,不然会出现insmod错误) 目的:通过android应用层用户 ...
- LM358电流检测电路
----------------------------------------------------------------------------------------- ---------- ...