Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 异位迁移:删除引用,保留字段_Postgresql_Elixir_Ecto - Fatal编程技术网

Postgresql 异位迁移:删除引用,保留字段

Postgresql 异位迁移:删除引用,保留字段,postgresql,elixir,ecto,Postgresql,Elixir,Ecto,在上一次迁移中,我定义了: create table(:my_table) do add :reference_id, references(:references), null: false (...) end 现在我想删除引用和null:false,但仍然保留reference\u id字段 所以我想要这样的东西: alter table(:my_table) do modify :reference_id, <SOME_TYPE>, null: true end

在上一次迁移中,我定义了:

create table(:my_table) do
  add :reference_id, references(:references), null: false
  (...)
end
现在我想删除引用和
null:false
,但仍然保留
reference\u id
字段

所以我想要这样的东西:

alter table(:my_table) do
  modify :reference_id, <SOME_TYPE>, null: true
end
alter table(:my_table)do
modify:reference\u id,null:true
结束
我的DB是Postgres,所以我认为应该是:bigint

我有两个问题: -以上是正确的吗?
-如果理解正确,此迁移无法直接回滚,因此我必须创建
up
down
函数。如果该代码在我的迁移的
向上
中,那么
向下
中应该包含什么?

bigint
在我看来是正确的<默认情况下,Ecto将PostgreSQL中的code>id字段定义为
bigint
类型

modify
采用与
add
相同的参数,因此您的up代码为:

modify :reference_id, :bigint, null: true
modify :reference_id, references(:references), null: false
下面是:

modify :reference_id, :bigint, null: true
modify :reference_id, references(:references), null: false
编辑:

使用外键约束时,向下键将不起作用,除非您删除
向上
中的外键约束,如下所示:

drop约束(:my\u table,“my\u table\u reference\u id\u fkey”)