# Ecommerce Plugin Error: Duplicate Entry '1' for key 'default\_site\_id'

**URL:** <https://discuss.openedx.org/t/ecommerce-plugin-error-duplicate-entry-1-for-key-default-site-id/9463>\
**Category:** Development\
**Tags:** ecommerce, tutor\
**Created:** [February 28, 2023, 7:07am UTC](https://discuss.openedx.org/t/ecommerce-plugin-error-duplicate-entry-1-for-key-default-site-id/9463 "2023-02-28T07:07:32Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Engr\_James\_Lusuegro](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/engr_james_lusuegro/32/4908_2.png) [@Engr\_James\_Lusuegro](https://discuss.openedx.org/u/Engr_James_Lusuegro)\
**Post date:** [February 28, 2023, 7:07am UTC](https://discuss.openedx.org/t/ecommerce-plugin-error-duplicate-entry-1-for-key-default-site-id/9463/1 "2023-02-28T07:07:32Z")

</div>

I am having difficulties enabling my ecommerce plugin.  
For some point in time, we have upgraded our instance into the latest version of tutor (Olive).

However, upon upgrading, we’ve noticed that the ecommerce is disabled. So we’ve tried to enable it by enabling `mfe` and the `discovery` plugin then performing the following commands.

`tutor plugins enable ecommerce`  
`tutor config save`  
`tutor images build openedx`  
`tutor local launch`

Upon launching, I received the following error.

[Traceback.txt](https://discuss.openedx.org/uploads/short-url/oposETgpjimel1jHbYFHgdzGyhg.txt) (6.4 KB)

 ![clipboard_image_53604c5e7c5ea6ef](https://us1.discourse-cdn.com/flex020/uploads/openedx/original/2X/d/da1e843a9a9e845ade9660f00255b858d46220bc.jpeg)  
 ![clipboard_image_b472114ce1cbe417](https://us1.discourse-cdn.com/flex020/uploads/openedx/original/2X/e/eb43284c25b55c8a5caa158f5b12bd96999e321a.jpeg)

You may also ask some certain questions such as the `site_ids`. At our `https://domain/admin/sites/site/`, here are the registered site\_ids:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/openedx/original/2X/c/cbe05c4c614d43738da4b603d721453aa24adbc1.png)

We can’t delete the id `1` since it is referenced as a foreign key on some tables.

How should I address this error?

---

<div class="post-metadata">

**Author:** ![regis](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/regis/32/2640_2.png) [@regis](https://discuss.openedx.org/u/regis)\
**Post date:** [February 28, 2023, 9:02am UTC](https://discuss.openedx.org/t/ecommerce-plugin-error-duplicate-entry-1-for-key-default-site-id/9463/2 "2023-02-28T09:02:07Z")

</div>

Hi @Engr_James_Lusuegro, this error was also reported by @lpm0073 here: [openedx/ecommerce-job: django.db.utils.IntegrityError: (1062, "Duplicate entry '1' for key 'default\_site\_id'") · Issue #25 · overhangio/tutor-ecommerce · GitHub](https://github.com/overhangio/tutor-ecommerce/issues/25)  
Actually, the error occurs because the `create_or_update_site` script attempts to create a new partner object that points to the same site ID:

```auto
   File "/openedx/ecommerce/ecommerce/core/management/commands/create_or_update_site.py", line 206, in handle 
     partner.save() 

```

What are your partner codes?

(next time, please copy-paste error logs instead of posting screenshots. It makes it much easier for us to search logs. Also, it allows other users who face the same error to find your topic.)

---

<div class="post-metadata">

**Author:** ![Engr\_James\_Lusuegro](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/engr_james_lusuegro/32/4908_2.png) [@Engr\_James\_Lusuegro](https://discuss.openedx.org/u/Engr_James_Lusuegro)\
**Post date:** [February 28, 2023, 10:56pm UTC](https://discuss.openedx.org/t/ecommerce-plugin-error-duplicate-entry-1-for-key-default-site-id/9463/3 "2023-02-28T22:56:43Z")

</div>

Thank you for your reply. If you would look carefully at my post, I have a `Traceback.txt` file indicating the posted image’s error.

but I think you’re right so I’ll post it here either way

```auto
Traceback (most recent call last):
  File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 73, in execute
    return self.cursor.execute(query, args)
  File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 209, in execute
    res = self._query(query)
  File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 315, in _query
    db.query(q)
  File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/connections.py", line 239, in query
    _mysql.connection.query(self, query)
MySQLdb._exceptions.IntegrityError: (1062, "Duplicate entry '1' for key 'default_site_id'")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "./manage.py", line 11, in <module>
    execute_from_command_line(sys.argv)
  File "/openedx/venv/lib/python3.8/site-packages/django/core/management/ __init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/openedx/venv/lib/python3.8/site-packages/django/core/management/ __init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/openedx/venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/openedx/venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/openedx/ecommerce/ecommerce/core/management/commands/create_or_update_site.py", line 206, in handle
    partner.save()
  File "/openedx/venv/lib/python3.8/site-packages/django/db/models/base.py", line 739, in save
    self.save_base(using=using, force_insert=force_insert,
  File "/openedx/venv/lib/python3.8/site-packages/django/db/models/base.py", line 776, in save_base
    updated = self._save_table(
  File "/openedx/venv/lib/python3.8/site-packages/django/db/models/base.py", line 858, in _save_table
    updated = self._do_update(base_qs, using, pk_val, values, update_fields,
  File "/openedx/venv/lib/python3.8/site-packages/django/db/models/base.py", line 912, in _do_update
    return filtered._update(values) > 0
  File "/openedx/venv/lib/python3.8/site-packages/django/db/models/query.py", line 802, in _update
    return query.get_compiler(self.db).execute_sql(CURSOR)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1559, in execute_sql
    cursor = super().execute_sql(result_type)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1175, in execute_sql
    cursor.execute(sql, params)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 73, in execute
    return self.cursor.execute(query, args)
  File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 209, in execute
    res = self._query(query)
  File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/cursors.py", line 315, in _query
    db.query(q)
  File "/openedx/venv/lib/python3.8/site-packages/MySQLdb/connections.py", line 239, in query
    _mysql.connection.query(self, query)
django.db.utils.IntegrityError: (1062, "Duplicate entry '1' for key 'default_site_id'")
ERROR: 1
Error: Command failed with status 1: docker-compose -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.yml -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.prod.yml -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.tmp.yml --project-name tutor_local -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.jobs.yml -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.jobs.tmp.yml run --rm ecommerce-job sh -e -c ./manage.py migrate --noinput
./manage.py oscar_populate_countries --initial-only

./manage.py create_or_update_site \
  --site-id=1 \
  --site-domain=ecommerce.tmtg-clone.click:8130 \
  --site-name=dev \
  --partner-code=dev \
  --partner-name="Open edX - development" \
  --lms-url-root="http://tmtg-clone.click:8000" \
  --client-side-payment-processor=cybersource \
  --payment-processors=cybersource,paypal \
  --sso-client-id="ecommerce-sso-dev" \
  --sso-client-secret="CTCS23rz" \
  --backend-service-client-id="ecommerce-dev" \
  --backend-service-client-secret="eMCJ6NtJ" \
  --from-email=tmtcoredev@gmail.com \
  --payment-support-email=tmtcoredev@gmail.com \
  --payment-support-url="http://tmtg-clone.click:8000/support" \
  --discovery_api_url=http://discovery.tmtg-clone.click:8381/api/v1/ \
  --enable-microfrontend-for-basket-page=true \
  --payment-microfrontend-url="http://apps.tmtg-clone.click:1998/payment"

# Production site
./manage.py create_or_update_site \
  --site-id=2 \
  --site-domain=ecommerce.tmtg-clone.click \
  --site-name=prod \
  --partner-code=openedx \
  --partner-name="Open edX" \
  --lms-url-root="https://tmtg-clone.click" \
  --lms-public-url-root="https://tmtg-clone.click" \
  --client-side-payment-processor=cybersource \
  --payment-processors=cybersource,paypal \
  --sso-client-id="ecommerce-sso" \
  --sso-client-secret="CTCS23rz" \
  --backend-service-client-id="ecommerce" \
  --backend-service-client-secret="eMCJ6NtJ" \
  --from-email=tmtcoredev@gmail.com \
  --payment-support-email=tmtcoredev@gmail.com \
  --payment-support-url="https://tmtg-clone.click/support" \
  --discovery_api_url=https://discovery.tmtg-clone.click/api/v1/ \
  --enable-microfrontend-for-basket-page=true \
  --payment-microfrontend-url="https://apps.tmtg-clone.click/payment"

```

> [@regis](#):
>
> What are your partner codes?

also, what are partner codes?

---

<div class="post-metadata">

**Author:** ![Manish\_Hada](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/manish_hada/32/1651_2.png) [@Manish\_Hada](https://discuss.openedx.org/u/Manish_Hada)\
**Post date:** [March 1, 2023, 6:34am UTC](https://discuss.openedx.org/t/ecommerce-plugin-error-duplicate-entry-1-for-key-default-site-id/9463/4 "2023-03-01T06:34:08Z")

</div>

I faced the same problem when I was doing a migration from previous versions. If you look into the post shared by Regis, it is clearly pointing out this issue and you need to write little SQL command to migrate your partner code for existing transactions.

I did the same thing in my case and the problem is resolved.

---

<div class="post-metadata">

**Author:** ![Engr\_James\_Lusuegro](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/engr_james_lusuegro/32/4908_2.png) [@Engr\_James\_Lusuegro](https://discuss.openedx.org/u/Engr_James_Lusuegro)\
**Post date:** [March 1, 2023, 8:50am UTC](https://discuss.openedx.org/t/ecommerce-plugin-error-duplicate-entry-1-for-key-default-site-id/9463/5 "2023-03-01T08:50:33Z")

</div>

Upon reviewing my database, here is the `django_site` table.

```auto
+----+-----------------------+-----------------------+
| id | domain | name |
+----+-----------------------+-----------------------+
| 1 | example.com | example.com |
| 2 | coursebank.ph | coursebank.ph |
| 3 | courses.coursebank.ph | courses.coursebank.ph |
| 4 | tmtg-clone.click | tmtg-clone.click |
| 5 | tmtg-clone.click:8000 | tmtg-clone.click:8000 |
+----+-----------------------+-----------------------+

```

Based on your instructions [here](https://github.com/overhangio/tutor-ecommerce/issues/25), I should replace the site\_ids `1` and `2`. What should I replace `dev` and `openedx` with? The `domain` or the `name`?

Also what would be its effects?  
Please bear with my lack of knowledge here since I’m a complete beginner in `tutor`. So there will be certain cases that I don’t even understand even this simple `partner codes`. I don’t know where to find it and I apologize in that matter.  
I will be waiting for some explanation and more accurate assistance before proceeding.

---

<div class="post-metadata">

**Author:** ![Engr\_James\_Lusuegro](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/engr_james_lusuegro/32/4908_2.png) [@Engr\_James\_Lusuegro](https://discuss.openedx.org/u/Engr_James_Lusuegro)\
**Post date:** [March 2, 2023, 10:48am UTC](https://discuss.openedx.org/t/ecommerce-plugin-error-duplicate-entry-1-for-key-default-site-id/9463/6 "2023-03-02T10:48:48Z")

</div>

Hello @regis

I’ve noticed that in the Traceback error:

```auto
Error: Command failed with status 1: docker-compose -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.yml -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.prod.yml -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.tmp.yml --project-name tutor_local -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.jobs.yml -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.jobs.tmp.yml run --rm ecommerce-job sh -e -c ./manage.py migrate --noinput
./manage.py oscar_populate_countries --initial-only

./manage.py create_or_update_site \
  --site-id=1 \
  --site-domain=ecommerce.tmtg-clone.click:8130 \
  --site-name=dev \
  --partner-code=dev \
  --partner-name="Open edX - development" \
  --lms-url-root="http://tmtg-clone.click:8000" \
  --client-side-payment-processor=cybersource \
  --payment-processors=cybersource,paypal \
  --sso-client-id="ecommerce-sso-dev" \
  --sso-client-secret="CTCS23rz" \
  --backend-service-client-id="ecommerce-dev" \
  --backend-service-client-secret="eMCJ6NtJ" \
  --from-email=tmtcoredev@gmail.com \
  --payment-support-email=tmtcoredev@gmail.com \
  --payment-support-url="http://tmtg-clone.click:8000/support" \
  --discovery_api_url=http://discovery.tmtg-clone.click:8381/api/v1/ \
  --enable-microfrontend-for-basket-page=true \
  --payment-microfrontend-url="http://apps.tmtg-clone.click:1998/payment"

# Production site
./manage.py create_or_update_site \
  --site-id=2 \
  --site-domain=ecommerce.tmtg-clone.click \
  --site-name=prod \
  --partner-code=openedx \
  --partner-name="Open edX" \
  --lms-url-root="https://tmtg-clone.click" \
  --lms-public-url-root="https://tmtg-clone.click" \
  --client-side-payment-processor=cybersource \
  --payment-processors=cybersource,paypal \
  --sso-client-id="ecommerce-sso" \
  --sso-client-secret="CTCS23rz" \
  --backend-service-client-id="ecommerce" \
  --backend-service-client-secret="eMCJ6NtJ" \
  --from-email=tmtcoredev@gmail.com \
  --payment-support-email=tmtcoredev@gmail.com \
  --payment-support-url="https://tmtg-clone.click/support" \
  --discovery_api_url=https://discovery.tmtg-clone.click/api/v1/ \
  --enable-microfrontend-for-basket-page=true \
  --payment-microfrontend-url="https://apps.tmtg-clone.click/payment"

```

I should hard code my database by changing

`site_id 1`’s :  
`domain` into `ecommerce.tmtg-clone.click:8130`,  
`partner-code` into `dev` and  
`site-name` into `dev`

while on `site_id 2`’s :  
`domain` into `ecommerce.tmtg-clone.click`,  
`partner-code` into `openedx` and  
`site-name` into `prod`

How can I do it? I mean I can change the `domain` and `name` in MySQL, but there is no `partner-code` column on my database. Will be waiting for your replies.

---

<div class="post-metadata">

**Author:** ![regis](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/regis/32/2640_2.png) [@regis](https://discuss.openedx.org/u/regis)\
**Post date:** [March 2, 2023, 11:56am UTC](https://discuss.openedx.org/t/ecommerce-plugin-error-duplicate-entry-1-for-key-default-site-id/9463/7 "2023-03-02T11:56:04Z")

</div>

DO NOT CHANGE SITE IDs!!! It will break your database.

You should only change your partner codes. To do that, you should open the ecommerce /admin page and search for partner objects there. On a local installation the url is: [http://ecommerce.local.overhang.io/admin/partner/partner/](http://ecommerce.local.overhang.io/admin/partner/partner/) Select the right partners and set their code to either “openedx” (in production) or “dev” (in development).

---

<div class="post-metadata">

**Author:** ![Manish\_Hada](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/manish_hada/32/1651_2.png) [@Manish\_Hada](https://discuss.openedx.org/u/Manish_Hada)\
**Post date:** [March 3, 2023, 6:39am UTC](https://discuss.openedx.org/t/ecommerce-plugin-error-duplicate-entry-1-for-key-default-site-id/9463/8 "2023-03-03T06:39:56Z")

</div>

But I guess, this issue again came when he going to run quickstart again.

---

<div class="post-metadata">

**Author:** ![Engr\_James\_Lusuegro](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/engr_james_lusuegro/32/4908_2.png) [@Engr\_James\_Lusuegro](https://discuss.openedx.org/u/Engr_James_Lusuegro)\
**Post date:** [March 4, 2023, 11:58am UTC](https://discuss.openedx.org/t/ecommerce-plugin-error-duplicate-entry-1-for-key-default-site-id/9463/9 "2023-03-04T11:58:14Z")

</div>

> [@regis](#):
>
> DO NOT CHANGE SITE IDs!!! It will break your database.
> 
> You should only change your partner codes. To do that, you should open the ecommerce /admin page and search for partner objects there. On a local installation the url is: [http://ecommerce.local.overhang.io/admin/partner/partner/](http://ecommerce.local.overhang.io/admin/partner/partner/) Select the right partners and set their code to either “openedx” (in production) or “dev” (in development).

When I go to [https://ecommerce.domain.com](https://ecommerce.domain.com),

it looks like this:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/openedx/original/2X/2/2a12548d233a58421fe11f74f50119a6d2db0ba3.png)

and when I go to the url [https://ecommerce.domain.com/admin/](https://ecommerce.domain.com/admin/), my account doesn’t login on it despite being a staff user. Why is that? @regis

Also, the `ecommerce` plugin is not even installed in the first place so how can I access this url?

---

<div class="post-metadata">

**Author:** ![Engr\_James\_Lusuegro](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/engr_james_lusuegro/32/4908_2.png) [@Engr\_James\_Lusuegro](https://discuss.openedx.org/u/Engr_James_Lusuegro)\
**Post date:** [March 6, 2023, 1:14am UTC](https://discuss.openedx.org/t/ecommerce-plugin-error-duplicate-entry-1-for-key-default-site-id/9463/10 "2023-03-06T01:14:14Z")

</div>

Hello @regis I’ve tried accessing the `ecommerce` database through mysql. I’ve realized that though it’s not installed, a partner code should be available here since we have an ecommerce before from our native instance.

```auto
mysql> select * from partner_partner;
+----+------+----------+------------+-----------------+
| id | code | name | short_code | default_site_id |
+----+------+----------+------------+-----------------+
| 1 | edX | Open edX | edX | 1 |
| 2 | dev | | | NULL |
+----+------+----------+------------+-----------------+
2 rows in set (0.00 sec)

```

So based on here, I’ve seen the partner codes you are pertaining to. I will try to rename it through hardcode.

• Are there any things I should be considering other than this?  
• and also, just to be clear, should I change id into `1` into `dev` and id `2` into `openedx`.?

I hope I am on the right track

---

<div class="post-metadata">

**Author:** ![sambapete](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/sambapete/32/4100_2.png) [@sambapete](https://discuss.openedx.org/u/sambapete)\
**Post date:** [March 6, 2023, 2:30pm UTC](https://discuss.openedx.org/t/ecommerce-plugin-error-duplicate-entry-1-for-key-default-site-id/9463/11 "2023-03-06T14:30:45Z")

</div>

We ran into a similar problem when we migrated from Native Koa to Tutor Koa. In fact, the problem occurred when we then migrated from Tutor Koa to Tutor Lilac.

I generally agree with @regis and I would not recommend to CHANGE SITE IDs. Unfortunately we did after a very careful reverse engineering of the ecommerce database under Native and under Tutor.

In the end, it worked for us, but I would not recommend doing it the way we did it.

It was a three steps process.

First, editing the ecommerce dump file from Koa Native to remove some tables for which we wanted to use the values generated by the default Tutor installation.

Second, restoring our new ecommerce dump in Tutor.

Third, running a script that would switch in multiple tables the values of site\_id from 1 to 2 and values of partner\_id from 1 to 2. That’s because our values where the reverse of what was created by Tutor in both the django\_site and partner\_partner tables. Our django\_site for dev was 2 and for prod it was 1. The same for partner\_partner. This might differ for you since you have id 4 and id 5 in your django\_site table. I am guessing that id 2 and id 3 where created at some point in the past from a previous installation under Native.

We could share what we did, but we do not feel comfortable making it public because every migration could be different and the values to change could also be different.

You would need to analyze the content of your database in order for it to make sense for your own installation.
