"Cannot find primary key" error for postgres tbl
See original GitHub issueI’m trying to run platformatic on an existing postgres db by setting connection string directly and bypassing migration. on npx platformatic db start
I get the following error Error: Cannot find primary key for Advert entity
.
The adverts table has the following DDL:
-- idkdb.adverts definition
-- Drop table
-- DROP TABLE idkdb.adverts;
CREATE TABLE idkdb.adverts (
id serial4 NOT NULL,
image_url varchar NOT NULL,
thumbnail_url varchar NOT NULL,
name varchar NOT NULL,
description varchar NOT NULL,
link varchar NOT NULL,
last_displayed timestamp NULL,
created_at timestamp NOT NULL DEFAULT now(),
CONSTRAINT adverts_pkey PRIMARY KEY (id)
);
Any idea what could be causing this?
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Postgres: Unable to set primary key on a column
Firstly you are missing data types for user_id and matched_profile . You are also using serial when you should be using INT GENERATED...
Read more >Cannot get anything with primaryKey to work with Postgres ...
Imagine a scenario when the table is not created in the database yet. Running this code 2 times in a row should be...
Read more >Documentation: 8.2: CREATE TABLE - PostgreSQL
The primary key constraint specifies that a column or columns of a table may contain ... Currently, CHECK expressions cannot contain subqueries nor...
Read more >Troubleshooting migration tasks in AWS Database Migration ...
To solve this issue, the current approach is to first precreate the tables and primary keys in the target database. Then use a...
Read more >Database schema missing many primary keys - breaks ...
On both modern MySQL and PostgreSQL systems, replication requires tables have primary keys in order to function properly.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Discussed with @ivan-tymoshenko offline. This was caused by using a connection string for a user without DDL permissions. See https://github.com/platformatic/platformatic/issues/161 for follow-up.
While troubleshooting, we ran into another a similar “Cannot find primary key” error. In this case, the table only has a foreign key without a primary key:
Indeed, it would essentially be a read-only table. What’s interesting is that you could still use it for nested references.