经过各种谷歌搜索后,我仍然对选择一个不在PostgreSQL默认公共模式下的表的问题感到头疼。
但是,我尝试在模型定义中引用Postgres的架构,但没有运气,并查看日志,我看到为什么它被查询“引用”
schema "nonpublicschema.sometable" do
field :somefield, :string
end
抛出:
ERROR | relation "nonpublicschema.sometable" does not exist
ERROR | SELECT u0."somefield" FROM "nonpublicschema.sometable" AS u0
我明白这不是一个错误,但我想知道我还能做到这一点。
答案 0 :(得分:3)
很遗憾,我们不支持您定义的方法。请打开一个问题,我们可以改进它。
与此同时,还有一些工作要做。你需要Ecto 1.0.2。对于查询,您可以设置前缀:
C:\Anaconda\lib\site-packages\IPython\config.py:13: ShimWarning:
The`IPython.config` package has been deprecated. You should import from
traitlets.config instead.
"You should import from traitlets.config instead.", ShimWarning)
C:\Anaconda\lib\site-packages\IPython\terminal\console.py:13: ShimWarning:
The `IPython.terminal.console` package has been deprecated. You should
import from jupyter_console instead.
"You should import from jupyter_console instead.", ShimWarning)
C:\Anaconda\lib\site-packages\IPython\frontend.py:21: ShimWarning: The top-
level `frontend` package has been deprecated. All its subpackages have been
moved to the top `IPython` level.
"All its subpackages have been moved to the top `IPython` level.",
ShimWarning)
Traceback (most recent call last):
File "C:\Users\Vladimir\AppData\Roaming\Sublime Text
3\Packages/SublimeREPL/config/Python/ipy_repl.py", line 45, in <module>
from IPython.frontend.terminal.console.app import ZMQTerminalIPythonApp
ImportError: No module named app
对于模型,您需要执行以下操作:
query = from p in Model, ...
query = %{query | prefix: "nonpublicschema"}
或者,您可以在存储库中定义model = Ecto.Model.put_meta model, prefix: "nonpublicschema"
回调,并使用Postgrex API自动扩展搜索路径。