2

我想知道是否有人可以告诉我如何SQLLaravel 4Schema Builder 中编写以下内容?

CREATE TABLE `conversation_reply` (
`cr_id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`reply` text,
`user_id_fk` int(11) NOT NULL,
`ip` varchar(30) NOT NULL,
`time` int(11) NOT NULL,
`c_id_fk` int(11) NOT NULL,
FOREIGN KEY (user_id_fk) REFERENCES users(user_id),
FOREIGN KEY (c_id_fk) REFERENCES conversation(c_id)
);
4

2 回答 2

6

如果我理解您的要求,这应该很接近;

Schema::table('conversation_reply', function($table)
{
    $table->increments('cr_id');
    $table->text('reply')->nullable();
    $table->foreign('user_id_fk')->references('user_id')->on('users');
    $table->string('ip', 30);
    $table->integer('time');
    $table->foreign('c_id_fk')->references('c_id')->on('conversation');
});
于 2013-06-12T16:57:30.643 回答
1

执行以下操作:

下面的 Schema 将进入下的 schema-migrations 文件public function up()

//Create ** category table **

    Schema:Create ('category',function ($table)){

                //Relation: category table id used as FK -> to -> product table category_id
                $table->increments('category_id');
                //category name
                $table->string('category_name',40)->unique();
                //time staps: created,Updated
                $table->timestamps();
    }

比,内部产品架构:

            //Create ** product table **

            Schema::create('products', function ($table){

                //product id
                $table->increments('product_id');
                //product name
                $table->string('p_name')->unique();
                //product description
                $table->text('p_description');
                //created_at and  updated_at column
                $table->timestamps();
                //Foregine Key
                $table->integer('category_id_fk')->unsigned();
                //Foreign Key link to category table
              $table->foreign('category_id_fk')->references('category_id')->on('category');
         }
于 2013-11-04T02:07:51.843 回答