doutu4335 2018-11-19 19:04
浏览 37
已采纳

如何通过迁移在laravel 5.7中创建非空列?

How can I create non-null columns in laravel 5.7 by migrating?

$table->string('title','50')->nullable();

does not work.
What can I do?

  • 写回答

1条回答 默认 最新

  • doudian6229 2018-11-19 19:11
    关注

    When you migrate to add a column to a table that already has records, you will need to make it nullable, or at least give it a default. Otherwise what would the value be for all of your current records?

    Worst case scenario if you have no default value, make it nullable. Then go through and set the value for each one, then remove the nullable.

    Your second migration (to remove nullability) would be like this:

    $table->string('title','50')->nullable(false)->change();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?