Deleted Space, want to set up again - Error: "a space with this space key already exists"
Asked by MJP:

1. I deleted a space.

2. I want to set up a new space (via a default space template) with the same name and the same SPACE KEY as the deleted one.

Confluence throws the error message "A space with this space key already exists".  
(as in german language: "Es existiert bereits ein Bereich mit diesem Bereichsschl?ssel.)

Note: I deleted the whole space, not only the space home page.

What can I do? The department needs their acronym as space key, I cannot just set any other name.


Answers:
author: MJP
body: I am a little confused at the moment.

When I checked the spaces list on the dashboard one day later, there suddenly my deleted space **reappeared**.

I am 100% sure that I deleted the space (by the procedure explained in <https://confluence.atlassian.com/display/DOC/Deleting+a+Space> ).

All we did was flush the caches and wait one day.No messing with the database, no server reboot.

-----------------------

Well, **I tried again** and was able to **successfully** delete and set up the space again this time.   
No problems with a duplicate space key...

Anyway, I would like to **thank you for your help**!


author: Gail Stewart
body: I have just recently created a jira project, then deleted it and re-created it, so in Jira you can do this.

comments: author: Isaac Montes
body: You are right I believe that is the way it used to be. I've always had that idea.  
Thanks for the update :)


author: Matthew Jaffe
body: I got this error after deleting a project. What I later realized was that, even though I deleted the project, an Agile board for the project somehow stuck around. After I deleted the stray board, all worked as expected.


author: MJP
body: I would like to avoid messing with the database.

Just remembered that a restart of the server or flushing the caches might work...   
I will try tomorrow.

comments: author: Isaac Montes
body: Yes, I would defenitly try that before messing with DB.


author: Isaac Montes
body: It's always best practice to create backups before deleting, you might be able to recover the space/space key that way, then go from there.

Another option is to go straight to the database and try to delete all records from that space, (is never recomended to mess with the db, even if you know what you are doing).

**REMEMBER ALWAYS BACKUP BEFORE MAKING ANY CHANGES. BACKUP THE ENTIRE DB.**

See: [How to manually delete a space](https://confluence.atlassian.com/display/CONFKB/How+to+Manually+Delete+a+Space)

If any of these things don't work you might also need to delete the space ID and KEY from the table. Have not tested that so if you try BACKUP!


author: Rodrigo Girardi Adami
body: ```
Hello MJP,I heard some cases with the same problem that we are facing right now. Basically it seems that the spacekey is stuck in the database, and to fix this problem, we need to run the following SQL query, to see if the space still exist:SELECT * FROM spaces;If still exists, you can run a SQL statement to delete. But I highly suggest that you do a full backup of your instance before running any SQL query.If that doesn't work, you might have to change the space name, due the special character: ?This should do the trick.

Regards,
Rodrigo
```

comments: author: Yogesh Mude
body: HI [@Rodrigo Girardi Adami](/t5/user/viewprofilepage/user-id/781470)

I tried to delete the space from db but it gives me below error...

Ran the below Query

```
delete from spaces where spaceid = 31391745;
```

Error:

```
ERROR: update or delete on table "spaces" violates foreign key constraint "fklmweu06nft59g7mw1i1myorys" on table "content"
DETAIL: Key (spaceid)=(31391745) is still referenced from table "content".
********** Error **********

ERROR: update or delete on table "spaces" violates foreign key constraint "fklmweu06nft59g7mw1i1myorys" on table "content"
SQL state: 23503
Detail: Key (spaceid)=(31391745) is still referenced from table "content".
```


Tags: delete

space-key