柴油打印模式不会生成可连接的!对于外键postgresql

问题描述

我有两个具有多对多关系的表,我想对其进行连接。一张表存储用户,另一张表存储相机。多对多表用于存储用户可以访问的摄像机。多个用户可以访问一个摄像头,因此需要多对多表。这是架构:

CREATE TABLE cameras (
    camera_id uuid PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL UNIQUE,name text NOT NULL
);
CREATE TABLE users (
    user_id uuid PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL UNIQUE,username text NOT NULL UNIQUE,password text NOT NULL
);

这是连接这两者的多对多表:

CREATE TABLE users_cameras (
    users_cameras_id SERIAL PRIMARY KEY,camera_id uuid NOT NULL,user_id uuid NOT NULL,CONSTRAINT fk_camera_id
        FOREIGN KEY (camera_id)
            REFERENCES cameras (camera_id)
            ON DELETE CASCADE,CONSTRAINT fk_user_id
        FOREIGN KEY (user_id)
            REFERENCES users (user_id)
            ON DELETE CASCADE
);

当我运行 diesel print-schema 时,这是输出

table! {
    cameras (camera_id) {
        camera_id -> Uuid,name -> Text,}
}

table! {
    users (user_id) {
        user_id -> Uuid,username -> Text,password -> Text,}
}

table! {
    users_cameras (users_cameras_id) {
        users_cameras_id -> Int4,camera_id -> Uuid,user_id -> Uuid,}
}

allow_tables_to_appear_in_same_query!(
    cameras,users,users_cameras,);

这不会生成 joinable! 内容,这意味着我无法对这些表执行连接。是我的数据布局错误,还是柴油的限制?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)