如何使Laravel迁移更改并使列可以为空

时间:2018-05-10 06:56:37

标签: laravel database-design

我使用post_id unsigned创建了一个迁移。如何在新迁移中编辑post_id以使其成为<UserControl x:Class="Gui.Modules.Common.Chart.ChartSeriesView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:attachedProperties="clr-namespace:Gui.Core.AttachedProperties;assembly=Gui.Core" xmlns:common="clr-namespace:Gui.Modules.Common" mc:Ignorable="d" d:DataContext="{x:Static common:DesignData.ChartSeriesViewModel}" d:DesignHeight="300" d:DesignWidth="300" > <Grid> <ContentControl x:Name="ChartContentControl" attachedProperties:Win32Keeper.Control="{Binding Chart}"/> </Grid> </UserControl>

nullable()

2 个答案:

答案 0 :(得分:2)

创建迁移并添加您的up函数,如下所示:

$table->integer('post_id')->nullable()->change();

答案 1 :(得分:0)

class x
 has_one y
end

class y
 belongs_to x
end

x.create_y
x.y.present? #true

x.y.destroy
x.y.present? #true
x.reload.y.present? #false

更改迁移

 php artisan migrate:rollback

然后

$table->integer('post_id')->nullable();