# \[SOLVED\] ownCloud to Nextcloud migration - oc\_accounts foreign key constraint fails

**URL:** <https://help.nextcloud.com/t/solved-owncloud-to-nextcloud-migration-oc-accounts-foreign-key-constraint-fails/48635>\
**Category:** ℹ️ Support\
**Created:** [March 2, 2019, 2:26am UTC](https://help.nextcloud.com/t/solved-owncloud-to-nextcloud-migration-oc-accounts-foreign-key-constraint-fails/48635 "2019-03-02T02:26:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![plarwood](https://help.nextcloud.com/letter_avatar/plarwood/32/6_22734026db12803ebb3e059622ac3534.png) [@plarwood](https://help.nextcloud.com/u/plarwood)\
**Post date:** [March 2, 2019, 2:26am UTC](https://help.nextcloud.com/t/solved-owncloud-to-nextcloud-migration-oc-accounts-foreign-key-constraint-fails/48635/1 "2019-03-02T02:26:04Z")

</div>

Hi,

Today I attempted to migrate from ownCloud 10.0.10 to Nextcloud 12.0.13 following the manual process instructions here:

> **[Migration: ownCloud vs Nextcloud – Nextcloud](https://nextcloud.com/migration/)**
>
> Nextcloud is an open source, self-hosted file share and communication platform. Access & sync your files, contacts, calendars & communicate and collaborate across your devices. You decide what happens with your data, where it is and who can access...

Unfortunately I received the following error.

```
# su apache -s /bin/bash -c '/opt/rh/rh-php71/root/bin/php /domains/example.com/occ upgrade'
Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade
Set log level to debug
Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException: An exception occurred while executing 'DROP TABLE oc_accounts':
SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails
Update failed
Maintenance mode is kept active
Reset log level

```

I was hoping perhaps someone might be able to point me in the right direction on how to resolve this.

Let me know if any further information is required.

Database: MariaDB 5.5.60

Thanks,

Paul.

---

<div class="post-metadata">

**Author:** ![plarwood](https://help.nextcloud.com/letter_avatar/plarwood/32/6_22734026db12803ebb3e059622ac3534.png) [@plarwood](https://help.nextcloud.com/u/plarwood)\
**Post date:** [March 2, 2019, 8:09am UTC](https://help.nextcloud.com/t/solved-owncloud-to-nextcloud-migration-oc-accounts-foreign-key-constraint-fails/48635/2 "2019-03-02T08:09:03Z")

</div>

I found the foreign key constraint. Is it safe to drop this constraint?

```
MariaDB [(none)]> SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME
    -> FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
    -> WHERE REFERENCED_TABLE_SCHEMA = 'owncloud' AND REFERENCED_TABLE_NAME = 'oc_accounts';
+---------------------+------------------+---------------------+-----------------------+------------------------+
| TABLE_NAME | COLUMN_NAME | CONSTRAINT_NAME | REFERENCED_TABLE_NAME | REFERENCED_COLUMN_NAME |
+---------------------+------------------+---------------------+-----------------------+------------------------+
| oc_persistent_locks | owner_account_id | FK_F0C3D55BC901C6FF | oc_accounts | id |
+---------------------+------------------+---------------------+-----------------------+------------------------+
1 row in set (0.47 sec)
```

---

<div class="post-metadata">

**Author:** ![j-ed](https://help.nextcloud.com/user_avatar/help.nextcloud.com/j-ed/32/7281_2.png) [@j-ed](https://help.nextcloud.com/u/j-ed)\
**Post date:** [March 2, 2019, 9:33am UTC](https://help.nextcloud.com/t/solved-owncloud-to-nextcloud-migration-oc-accounts-foreign-key-constraint-fails/48635/3 "2019-03-02T09:33:02Z")

</div>

This is not the answer of your question but I would not try to migrate to an unsupported  
Nextcloud version. You should better try to mirate directly to Nextcloud 14.x/15.x, because  
these are supported versions.

---

<div class="post-metadata">

**Author:** ![plarwood](https://help.nextcloud.com/letter_avatar/plarwood/32/6_22734026db12803ebb3e059622ac3534.png) [@plarwood](https://help.nextcloud.com/u/plarwood)\
**Post date:** [March 3, 2019, 1:43am UTC](https://help.nextcloud.com/t/solved-owncloud-to-nextcloud-migration-oc-accounts-foreign-key-constraint-fails/48635/4 "2019-03-03T01:43:57Z")

</div>

That is not the recommended migration path. Quoting from the article: ‘You can update from ownCloud 10.0.10 and older to Nextcloud 12.0.12 after which you can use our update to move to a newer Nextcloud release’.

Reading that back now perhaps I should try 12.0.12 instead of 12.0.13?

---

<div class="post-metadata">

**Author:** ![Bernie\_O](https://help.nextcloud.com/user_avatar/help.nextcloud.com/bernie_o/32/40181_2.png) [@Bernie\_O](https://help.nextcloud.com/u/Bernie_O)\
**Post date:** [March 3, 2019, 4:53am UTC](https://help.nextcloud.com/t/solved-owncloud-to-nextcloud-migration-oc-accounts-foreign-key-constraint-fails/48635/5 "2019-03-03T04:53:56Z")

</div>

> [@plarwood](#):
>
> I found the foreign key constraint. Is it safe to drop this constraint?

All I can say is, that this query returns an `Empty set` on my two nextcloud instances. So it looks like it is not needed by nextcloud. Maybe, create a database dump first, drop this constraint and then have a look if the migration runs through successfully

> [@plarwood](#):
>
> perhaps I should try 12.0.12 instead of 12.0.13?

I would migrate to 12.0.13

> [@j-ed](#):
>
> You should better try to mirate directly to Nextcloud 14.x/15.x, because  
> these are supported versions.

This is not possible and not an allowed migration path. Migrations from ownCloud need to go through Nextcloud 12 and then have to be upgraded to supported versions ([Migrating from ownCloud — Nextcloud 15 Administration Manual 15 documentation](https://docs.nextcloud.com/server/15/admin_manual/maintenance/migrating_owncloud.html)).

---

<div class="post-metadata">

**Author:** ![plarwood](https://help.nextcloud.com/letter_avatar/plarwood/32/6_22734026db12803ebb3e059622ac3534.png) [@plarwood](https://help.nextcloud.com/u/plarwood)\
**Post date:** [March 4, 2019, 2:41am UTC](https://help.nextcloud.com/t/solved-owncloud-to-nextcloud-migration-oc-accounts-foreign-key-constraint-fails/48635/6 "2019-03-04T02:41:52Z")

</div>

I managed to successfully complete the migration.

The oc\_persistent\_locks had two constraints the one above on oc\_accounts and another on oc\_filecache. I had to drop both of them for the migration script to complete successfully.

Over the next few weekends I will update Nextcloud to a supported version.

Thank you for the assist.

---

<div class="post-metadata">

**Author:** ![strozzascotte](https://help.nextcloud.com/user_avatar/help.nextcloud.com/strozzascotte/32/13880_2.png) [@strozzascotte](https://help.nextcloud.com/u/strozzascotte)\
**Post date:** [March 9, 2019, 11:18pm UTC](https://help.nextcloud.com/t/solved-owncloud-to-nextcloud-migration-oc-accounts-foreign-key-constraint-fails/48635/7 "2019-03-09T23:18:19Z")

</div>

Thanks for this. I had the same issue. Solved deleting the same two constraints.

---

<div class="post-metadata">

**Author:** ![vbonnefille](https://help.nextcloud.com/letter_avatar/vbonnefille/32/6_22734026db12803ebb3e059622ac3534.png) [@vbonnefille](https://help.nextcloud.com/u/vbonnefille)\
**Post date:** [July 30, 2024, 12:38pm UTC](https://help.nextcloud.com/t/solved-owncloud-to-nextcloud-migration-oc-accounts-foreign-key-constraint-fails/48635/8 "2024-07-30T12:38:36Z")

</div>

Hello  
I have the same issue,  
OCloud was installed (10.14.0)  
i try to upgrade Nextcloud  
(using my old OC config/data files)  
`php ./occ upgrade`

So I try

```sql
SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME
    -> FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
    -> WHERE REFERENCED_TABLE_SCHEMA = 'owncloud' AND REFERENCED_TABLE_NAME = 'oc_accounts';

```

But no line affected.  
How to reproduce ?

[EDIT]

```auto
SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = 'serendipvspip'

```

from [Migration owncloud 10.2.1 to NC 12.0.12 An exception occurred while executing 'DROP TABLE oc\_accounts' - #5 by sneo](https://help.nextcloud.com/t/migration-owncloud-10-2-1-to-nc-12-0-12-an-exception-occurred-while-executing-drop-table-oc-accounts/58381/5)  
output some thing… 2 FK\_…  
[/EDIT]

Thanks for the clues (and hope)

---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [January 16, 2025, 9:23am UTC](https://help.nextcloud.com/t/solved-owncloud-to-nextcloud-migration-oc-accounts-foreign-key-constraint-fails/48635/9 "2025-01-16T09:23:01Z")

</div>


