This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-04
Channels
- # announcements (7)
- # babashka (32)
- # beginners (106)
- # bristol-clojurians (10)
- # cider (6)
- # clj-kondo (5)
- # cljdoc (10)
- # clojure (110)
- # clojure-australia (10)
- # clojure-dev (6)
- # clojure-europe (12)
- # clojure-nl (2)
- # clojure-norway (16)
- # clojure-spec (9)
- # clojure-uk (59)
- # clojurescript (105)
- # community-development (2)
- # conjure (46)
- # cursive (12)
- # data-science (1)
- # datalog (26)
- # datomic (37)
- # docker (4)
- # emacs (10)
- # events (1)
- # fulcro (8)
- # graalvm (2)
- # jobs (1)
- # jobs-discuss (1)
- # malli (24)
- # meander (13)
- # off-topic (52)
- # pathom (4)
- # polylith (17)
- # proletarian (4)
- # react (1)
- # rewrite-clj (4)
- # shadow-cljs (56)
- # sql (21)
- # xtdb (14)
Can someone tell me why I’m getting an “architect_id” referenced in foreign key constraint does not exist when I attempt to make the cubes table. I literally copy/pasted the code that I used to create my ‘chamber’ table.
;; Create and Drop Databases
(defn create-db-tables []
(do
(db/execute! data-source
["create table if not exists architects(id SERIAL PRIMARY KEY,
handle VARCHAR(100),
password VARCHAR(100))"])
(db/execute! data-source
["create table if not exists books(id serial PRIMARY KEY,
title VARCHAR(1000),
author VARCHAR(100),
genre VARCHAR(50),
own BOOLEAN,
reading VARCHAR(10),
description TEXT,
pages INTEGER)"])
(db/execute! data-source
["create table if not exists chamber(id serial PRIMARY KEY,
architect_id INTEGER,
name VARCHAR(100),
created_at TIMESTAMP DEFAULT Now(),
CONSTRAINT fk_architect
FOREIGN KEY(architect_id)
REFERENCES architects(architect_id))"])
(db/execute! data-source
["create table if not exists cubes(id serial PRIMARY KEY,
architect_id INTEGER,
chamber_id INTEGER,
name VARCHAR(100),
created_at TIMESTAMP DEFAULT Now(),
CONSTRAINT fk_architect
FOREIGN KEY(architect_id)
REFERENCES architects(architect_id))"])
#_(db/execute! data-source
["create table if not exists cubes(id serial PRIMARY KEY,
architect_id INTEGER,
chamber_id INTEGER,
name VARCHAR(150),
created_at TIMESTAMP DEFAULT Now(),
CONSTRAINT fk_chamber
FOREIGN KEY(chamber_id)
REFERENCES chamber(chamber_id))"])
#_(db/execute! data-source
["create table if not exists iotas(book_id,
user_id)"])))
references architects(architects_id)
should probably be references architects(id)
right? there is no column named that
That cubes
/`chamber_id` code is commented out, that's why it doesn't fail.
esp. since clojure has you writing or generating sql directly instead of through a magic layer
@emccue yeah singular feels better. I’m coming from the world of ORM…. I’ll make that change. It did bug me.
and in the future, to paste multiline, use triple-backticks <body> triple-backticks
and it looks
nicer on the eyes
(and for something that large, use a snippet so it is collapsible and you get syntax highlighting as a bonus)
@dpsutton noted and I was wondering how that worked. I’ve been avoiding slack for the longest. Still learning the intricacies.
no worries. any channel will be happy to help out with formatting and stuff. and it should make your life much easier in the future 🙂
There's also a #slack-help channel if you have Qs about Slack itself, rather than Clojure, and #community-development if you have Qs about this community. Folks will be happy to help!