首页 > 数据库 >SQLC - ERROR: relation "accounts" does not exist

SQLC - ERROR: relation "accounts" does not exist

时间:2023-11-28 20:22:57浏览次数:32  
标签:sql db does accounts ERROR sqlc generate schema

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.

 

标签:sql,db,does,accounts,ERROR,sqlc,generate,schema
From: https://www.cnblogs.com/zhangzhihui/p/17862917.html

相关文章