6

I am using Strapi v3.0.0-beta.18.7

How to delete the ContentType and the related tables from DB ?

I tried the command below, but it is not deleting the db tables.

DELETE  http://localhost:1337/content-type-builder/content-types/application::CONTENT_TYPE_NAME.CONTENT_TYPE_NAME
Oksana B
  • 358
  • 1
  • 3
  • 17

4 Answers4

11

To delete the content-type and related db-tables in Strapi, You can delete the folder inside /api folder having same name as your content-type

enter image description here

Suppose if you want to delete the "product" content type, you can delete the product folder inside of /api

Srijan Katuwal
  • 151
  • 2
  • 8
5

The database's tables sync is not managed in the Content Type Builder plugin.

By default, Strapi doesn't delete anything from your database structure.

Strapi is customizable but you will not be able to update this.

Here is an issue that talks about this topic - https://github.com/strapi/strapi/issues/1114

Jim LAURIE
  • 3,859
  • 1
  • 11
  • 14
3

The answers above are really helpful but don't explain, how you would actually go about deleting the table manually.

Suppose you run a local default installation with sqlite, you can find your database at .tmp/data.db. To connect to it, you will need a tool that you can get from sqlite directly: https://sqlite.org/download.html

I guess you can add it to the PATH, but since I am a beginner and I just wanted it to work, i put the sqlite3.exe directly in the folder of the database and ran it.

  • To open the database, I used .open data.db and tested it with .tables which showed me all the tables that strapi created for me but didn't delete.
  • To ensure that I found the right table (recipe-cuisine) i looked at the content using .headers on followed by SELECT * FROM "recipe-cuisine";.
  • I finally deleted the whole table using DROP TABLE "recipe-cuisine";.

There is an awesome documentation on how to do other operations here: https://www.sqlitetutorial.net/

I hope that helps other beginners who struggle to delete the tables. If anybody has suggestions or helpful links with more information, that would be great!

3

Lets assume you need remove abc collection.

WARNING

Be sure you created backup and there are not other collections that contains abc substring.

Then you need execute commands:

DELETE FROM `users-permissions_permission` WHERE `controller` LIKE '%abc%';
DELETE FROM strapi_permission WHERE `subject` LIKE '%abc%';
DELETE FROM core_store WHERE `key` LIKE '%abc%';
DELETE FROM upload_file_morph WHERE related_type LIKE '%abc%';
DROP TABLE abc;

Then you need execute also:

rm -rf api/abc

Additional notes:

  • take care about plural names
  • be sure that there are no relations with other tables in other case you will see error
TypeError: Cannot read property 'globalId' of undefined
Daniel
  • 7,684
  • 7
  • 52
  • 76