Changing column name on primary key column makes Admin inaccessable

System Information
  • Strapi Version: 4.0.7
  • Operating System: Ubuntu 20.04.3 LTS
  • Database: PG 13.4
  • Node Version: v12.22.7
  • NPM Version: 6.14.15
  • Yarn Version: 1.22.17

I was changing my column names and I broke my database in such a way that I cannot load Strapi. I tried logging into Postgres to drop the tables but the table ‘seeds’ did not exist. How do I get Strapi out of this funk? My Strapi Server is not under version control but I did make a backup of the database image.

[2022-03-13 03:32:03.153] debug: ⛔️ Server wasn't able to start properly.
[2022-03-13 03:32:03.155] error: alter table "seeds" alter column "id" drop not null - column "id" is in a primary key
error: alter table "seeds" alter column "id" drop not null - column "id" is in a primary key
    at Parser.parseErrorMessage (/srv/strapi-azure/node_modules/pg-protocol/dist/parser.js:287:98)
    at Parser.handlePacket (/srv/strapi-azure/node_modules/pg-protocol/dist/parser.js:126:29)
    at Parser.parse (/srv/strapi-azure/node_modules/pg-protocol/dist/parser.js:39:38)
    at TLSSocket.<anonymous> (/srv/strapi-azure/node_modules/pg-protocol/dist/index.js:11:42)
    at TLSSocket.emit (events.js:314:20)
    at TLSSocket.EventEmitter.emit (domain.js:483:12)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at TLSSocket.Readable.push (_stream_readable.js:213:10)
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:188:23)
error Command failed with exit code 1.

Is there some sort of safe mode?

There is a table in the database that keeps a history of the schema. By manually editing the schema you’ve thrown Strapi out of sync.

You can try to delete the strapi_database_schema table and restart to see if that fixes it.

To be clear there is no way to change the id type or name right now.

(If you want to change other field column names you can use this unstable API: Models - Strapi Developer Docs )

Thank you for your help. Is there any way version control could have prevented me from having to drop the database?

Also, the system shouldn’t allow me to destroy my own db! I will put in a bug report.

@DMehaffy that didn’t work. is there a more forcefull way to wipe the database without doing a completely new install? Or, what is the best way to do a completely new install and migrate my connections, plugins, etc.?

I created a new database and a new app and started over. Next time I will keep Strapi in version control. It seems the schema is stored in the JavaScript.