dping1968 2019-05-28 14:53
浏览 57

如何在Blueprint中重新定义列

Background

I am trying to extend class Blueprint to make my Blueprint.Finally,I found the way .But when I made attempt to overwrite some ColumnDefinition ,some trouble stopped me.

Problem 1

 Schema::create('Person',function(Blueprint $table){
    $table->string('id')->comment('身份证号');
    $table->string('id')->comment('学号')->change();//this line doesn't work!
});

Like the code above,the second line in that Closure doesn't work and i don't know why.

What I know is that some 'Modify Cloumn' operations need a dependency called doctrine/dbal and I have installed it.

The function change() neither reports any error nor meets expectation.It is strange.

Please help me!

Problem 2

By reading the source code of Schema,I found the relationship between Schema and Blueprint is Schema->Builder->Blueprint.Schema::create() will call $blueprint->create() before the Closure function(Blueprint $table).It seems that it is the same effect whether I define the fields in the Closure or directly put the field definitions in the $blueprint->__constructor().But,when I run migrate,the Blueprint's constructor is called more than once.If I put all of the column definitions in that Closure,everyting is fine.Strange!

And,I also noticed that $table->unique() finally becomes alter table $table add unique,why not compile command before creating like create table $table(...,unique key $keyname (k1,k2,)).

At present,I believe that Blueprint saves column definitions in a array $commands[] and finally compiles the commands into sql.If so,why not support overwrite when before table is created?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么