Laravel:使用Migrations

1、首先利用artisan创建一个可迁移的数据表模板,该命令运行后会在database/migrations目录下生成一个文件

php artisan make:migration create_fees_count_table --create=fees_count

2、生成的文件包含up和down两个方法,其中up中是包含了添加表,添加列,添加索引等等一切的描述,down比较简单,就是删除表,当然里面还可以有一些其他逻辑
3、up中支持的数据表列类型,做个备注,暂时不做翻译

CommandDescription
$table->bigIncrements('id');Incrementing ID (primary key) using a "UNSIGNED BIG INTEGER" equivalent.
$table->bigInteger('votes');BIGINT equivalent for the database.
$table->binary('data');BLOB equivalent for the database.
$table->boolean('confirmed');BOOLEAN equivalent for the database.
$table->char('name', 4);CHAR equivalent with a length.
$table->date('created_at');DATE equivalent for the database.
$table->dateTime('created_at');DATETIME equivalent for the database.
$table->decimal('amount', 5, 2);DECIMAL equivalent with a precision and scale.
$table->double('column', 15, 8);DOUBLE equivalent with precision, 15 digits in total and 8 after the decimal point.
$table->enum('choices', ['foo', 'bar']);ENUM equivalent for the database.
$table->float('amount');FLOAT equivalent for the database.
$table->increments('id');Incrementing ID (primary key) using a "UNSIGNED INTEGER" equivalent.
$table->integer('votes');INTEGER equivalent for the database.
$table->json('options');JSON equivalent for the database.
$table->jsonb('options');JSONB equivalent for the database.
$table->longText('description');LONGTEXT equivalent for the database.
$table->mediumInteger('numbers');MEDIUMINT equivalent for the database.
$table->mediumText('description');MEDIUMTEXT equivalent for the database.
$table->morphs('taggable');Adds INTEGER taggable_id and STRING taggable_type.
$table->nullableTimestamps();Same as timestamps(), except allows NULLs.
$table->rememberToken();Adds remember_token as VARCHAR(100) NULL.
$table->smallInteger('votes');SMALLINT equivalent for the database.
$table->softDeletes();Adds deleted_at column for soft deletes.
$table->string('email');VARCHAR equivalent column.
$table->string('name', 100);VARCHAR equivalent with a length.
$table->text('description');TEXT equivalent for the database.
$table->time('sunrise');TIME equivalent for the database.
$table->tinyInteger('numbers');TINYINT equivalent for the database.
$table->timestamp('added_on');TIMESTAMP equivalent for the database.
$table->timestamps();Adds created_at and updated_at columns.
$table->uuid('id');UUID equivalent for the database.

4、表创建完成后,直接执行,由于我之前很多表创建并没有使用php artisan migrate,所以直接运行该命令导致提示部分表存在,所以,我把这个文件转移到database下tmp目录下,命令上添加 --path 'database/tmp',再次运行成功

php artisan  migrate 

5、数据库中观察即发现表已创建!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值