Laravel5.6数据库操作 —— 迁移

作者: 蚂蚁窝大梦想 | 来源:发表于2019-02-14 16:05 被阅读5次

Laravel 的 Schema 门面提供了与数据库系统无关的创建和操纵表的支持,在 Laravel 所支持的所有数据库系统中提供一致的、优雅的、流式的 API。

一、生成迁移

新的迁移位于 database/migrations 目录下,每个迁移文件名都包含时间戳从而允许 Laravel 判断其顺序。
--table--create 选项可以用于指定表名以及该迁移是否要创建一个新的数据表。这些选项只需要简单放在上述迁移命令后面并指定表名:

自定义输出路径,在执行 make:migration 命令时可以使用 --path 选项,提供的路径应该是相对于应用根目录的。

php artisan make:migration create_users_table
//创建表
php artisan make:migration create_users_table --create=users
//添加列
php artisan make:migration add_votes_to_users_table --table=usersx

二、运行迁移&回退

//运行迁移
php artisan migrate
//回退迁移 --step=5指定回退数目
php artisan migrate:rollback

相关文章

网友评论

    本文标题:Laravel5.6数据库操作 —— 迁移

    本文链接:https://www.haomeiwen.com/subject/cfbeeqtx.html