migrations创建数据表--Dcat-Admin框架实战(一)

目录

一、创建数据表

二、编辑数据表内容

三、在MySQL数据库中创建数据表

报错解决(1)

四、验证


一、创建数据表

1、进入项目目录(这里我的项目目录是test10)

cd test10

2、创建数据表(这里我的数据表名为hardware_records)(更多博文,欢迎来我的博客学习交流https://blog.csdn.net/have_a_cat

php artisan make:migration create_hardware_records_table --table=hardware_records

#想创建的数据表名为hardware_records

#想创建的PHP文件名为create_hardware_records_tabl,将位于test10/database/migrations目录下

 

 

 

二、编辑数据表内容

1、打开刚才创建的PHP migrations文件2021_04_01_063026_create_hardware_records_table.php

 

2、编辑hardware_records表的列

    public function up()

    {

        Schema::create('hardware_records', function (Blueprint $table) {

            $table->string('id')->unique();

            $table->text('name');

            $table->text('brand');

            $table->text('type_id');

            $table->text('model');

            $table->text('motorroom_location')->nullable();/*(更多博文,欢迎来我的博客学习交流https://blog.csdn.net/have_a_cat)*/

            $table->text('cabinet_location')->nullable();

            $table->longText('contract_no')->nullable();

            $table->dateTime('maintenance_start')->nullable();

            $table->dateTime('insured_date')->nullable();

            $table->integer('remaining_daysofinsurance')->nullable();

        });

附:表hardware_records的列设计

三、在MySQL数据库中创建数据表

php artisan migrate
/*(更多博文,欢迎来我的博客学习交流https://blog.csdn.net/have_a_cat)*/

 

 

报错解决(1)

“php artisan migrate”执行成功了,MySQL数据库中却没有表(这里表名为hardware_records)。

 

解决:执行

php artisan migrate:fresh

 

 

四、验证

1、打开一个新的终端

2、连接MySQL数据库

mysql -uroot -p

#(这里用户名为root;密码为空)

 

 

3、连接database dcat_admin(更多博文,欢迎来我的博客学习交流https://blog.csdn.net/have_a_cat

connect dcat_admin;

 

4、列出database dcat_admin中所有数据表

show tables;

 

 

至此,我们已经成功创建数据表!

5、退出MySQL(更多博文,欢迎来我的博客学习交流https://blog.csdn.net/have_a_cat

quit;

 

 

写过Java后,发现这个PHP的Dcat-Admin框架是真的方便太多了,用migrations创建数据表分分钟完成。 --2021年4月1日

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值