strapi icon indicating copy to clipboard operation
strapi copied to clipboard

Server crash: `Duplicate column error` when renaming column by changing only one letter from uppercase to lowercase

Open marcj opened this issue 6 years ago • 3 comments

macOS 10.15.3 Node 12

Reproduction:

  1. npx create-strapi-app strapi-test1 --quickstart
  2. Add user
  3. Add new content type "Post" 3.1. Add "Title" short-text 3.2. Add "content" rich-text 3.3. Press "Save"
  4. Edit content type "Post" 4.1. Edit "Title", rename name to "title" (lowercase) 4.2. Press Save
  5. Restart happens. Error in console appears:
[2020-05-28T17:20:29.166Z] debug PUT /content-type-builder/content-types/application::post.post (32 ms) 201
[2020-05-28T17:20:29.167Z] info The server is restarting

[2020-05-28T17:20:30.082Z] debug ⛔️ Server wasn't able to start properly.
[2020-05-28T17:20:30.083Z] error Error: SQLITE_ERROR: duplicate column name: title
    at Client_SQLite3._query (/Users/marc/bude/strapi-test1/node_modules/knex/lib/dialects/sqlite3/index.js:99:12)
    at Client_SQLite3.query (/Users/marc/bude/strapi-test1/node_modules/knex/lib/client.js:158:17)
    at Runner.query (/Users/marc/bude/strapi-test1/node_modules/knex/lib/runner.js:135:36)
    at Runner.queryArray (/Users/marc/bude/strapi-test1/node_modules/knex/lib/runner.js:224:14)
    at /Users/marc/bude/strapi-test1/node_modules/knex/lib/runner.js:37:25
From previous event:
    at Runner.run (/Users/marc/bude/strapi-test1/node_modules/knex/lib/runner.js:25:16)
    at SchemaBuilder.Target.then (/Users/marc/bude/strapi-test1/node_modules/knex/lib/interface.js:14:43)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] develop: `strapi develop`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] develop script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/marc/.npm/_logs/2020-05-28T17_20_30_093Z-debug.log

After trying to manually start the server again, it fails:

[2020-05-28T17:20:53.762Z] debug ⛔️ Server wasn't able to start properly.
[2020-05-28T17:20:53.762Z] error Error: SQLITE_ERROR: duplicate column name: title
    at Client_SQLite3._query (/Users/marc/bude/strapi-test1/node_modules/knex/lib/dialects/sqlite3/index.js:99:12)
    at Client_SQLite3.query (/Users/marc/bude/strapi-test1/node_modules/knex/lib/client.js:158:17)
    at Runner.query (/Users/marc/bude/strapi-test1/node_modules/knex/lib/runner.js:135:36)
    at Runner.queryArray (/Users/marc/bude/strapi-test1/node_modules/knex/lib/runner.js:224:14)
    at /Users/marc/bude/strapi-test1/node_modules/knex/lib/runner.js:37:25
From previous event:
    at Runner.run (/Users/marc/bude/strapi-test1/node_modules/knex/lib/runner.js:25:16)
    at SchemaBuilder.Target.then (/Users/marc/bude/strapi-test1/node_modules/knex/lib/interface.js:14:43)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `strapi start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/marc/.npm/_logs/2020-05-28T17_20_53_773Z-debug.log

So, you're stuck basically. Since I don't know where the SQLite file is located I can't manually remove the table and start over.

marcj avatar May 28 '20 17:05 marcj

I am up-voting this issue. This is a serious error. I think, at least a validation in the UI is needed. image

samahudin avatar May 30 '20 05:05 samahudin

@marcj :

Since I don't know where the SQLite file is located I can't manually remove the table and start over.

Write or Wrong, In my cases I found the db in .tmp folder in the root of my project folder. I have opened it in an external db tool 'DB Browser'. And renamed my field in the classic SQLite way :

ALTER TABLE components_swoph_category_forms RENAME TO temp_components_swoph_category_forms; CREATE TABLE 'components_swoph_category_forms' ('id' integer not null primary key autoincrement, 'language' integer null, 'translation' varchar(255) null); INSERT INTO components_swoph_category_forms SELECT id, language, Translation FROM temp_components_swoph_category_forms; DROP TABLE temp_components_swoph_category_forms;

(BTW, you can get the create table statement from the Data Structure Tab of DB Browser.)

samahudin avatar May 30 '20 06:05 samahudin

duplicate: https://github.com/strapi/strapi/issues/5941

derrickmehaffy avatar May 31 '20 13:05 derrickmehaffy