zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    css dropdown menu
    Understanding Delegated JavaScript Events
    AngularJS-Learning ui-router angular-transitions
    javascript sorting/ v8 sorting
    Sublime Text 3 新手上路:必要的安裝、設定與基本使用教學
    express with bower in websotrm
    angularjs transitions
    create a nodejs npm package
    nodejs module/require
    stylus , another css processor
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/8215264.html
Copyright © 2011-2022 走看看