SQLC - ERROR: relation "accounts" does not exist

发布时间 2023-11-28 20:16:14作者: ZhangZhihuiAAA

Copied the example of sqlc.yaml generated by 'sqlc init' from https://docs.sqlc.dev/en/stable/tutorials/getting-started-postgresql.html# .

Changed it as following:

version: "2"
sql:
  - engine: "postgresql"
    queries: "db/sqlc/query"
    schema: "db/schema"
    gen:
      go:
        package: "db"
        out: "./db/sqlc"
        emit_json_tags: true

 

Ran 'sqlc generate':

zzh@ZZHPC:~/zd/Github/zimplebank$ sqlc generate
# package db
db/sqlc/query/account.sql:1:1: relation "accounts" does not exist

Got the above error. 

 

This was because there were two .sql files in directory "db/schema", and sqlc can't recognize the schema file. Changed the value of schema from db/schema" to "db/schema/0001_create_tables.sql", then 'sqlc generate' succeeded.