目录
一、创建数据表
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日