# Duplicate CDR data storing issue

**URL:** <https://community.asterisk.org/t/duplicate-cdr-data-storing-issue/101330>\
**Category:** Asterisk Dialplan\
**Created:** [March 5, 2024, 4:04am UTC](https://community.asterisk.org/t/duplicate-cdr-data-storing-issue/101330 "2024-03-05T04:04:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chandimadharmarathne](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/chandimadharmarathne/32/7497_2.png) [@chandimadharmarathne](https://community.asterisk.org/u/chandimadharmarathne)\
**Post date:** [March 5, 2024, 4:04am UTC](https://community.asterisk.org/t/duplicate-cdr-data-storing-issue/101330/1 "2024-03-05T04:04:58Z")

</div>

Hello, In my asterisk, I created database using MariaDB. Also I created data table called CDR for storing call details in my database. But After each call, it saved data with duplicate. I mean save same data set twice. How fix this issue?

```auto
| 66 | 2024-03-05 09:26:04 | "773xxxxxx" <773xxxxxx> | 773xxxxxx| s | testing | PJSIP/registrar-00000000 | NULL | BackGround | welcomedmse | 4 | 4 | ANSWERED | 3 | NULL | 1709610964.0 | NULL | 1709610964.0 |
| 67 | 2024-03-05 09:26:04 | "773xxxxxx" <773xxxxxx> | 773xxxxxx| s | testing | PJSIP/registrar-00000000 | | BackGround | welcomedmse | 4 | 4 | ANSWERED | 3 | | NULL | | 1709610964.0 |
+

```

---

<div class="post-metadata">

**Author:** ![danishhafeez](https://avatars.discourse-cdn.com/v4/letter/d/977dab/32.png) [@danishhafeez](https://community.asterisk.org/u/danishhafeez)\
**Post date:** [March 5, 2024, 6:00am UTC](https://community.asterisk.org/t/duplicate-cdr-data-storing-issue/101330/2 "2024-03-05T06:00:45Z")

</div>

To prevent duplicate entries in your CDR table, you can add a unique constraint to the appropriate columns in your database schema.

`ALTER TABLE CDR ADD CONSTRAINT unique_cdr_entry UNIQUE (call_id);`

Replace `call_id` with the appropriate column name that uniquely identifies each call entry. This constraint ensures that no duplicate entries with the same `call_id` will be inserted into the table.  
i hope it will work for you.

Best regard  
Danish Hafeez | QA Assistant  
[ICTInnovations](https://www.ictinnovations.com)

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [March 5, 2024, 1:32pm UTC](https://community.asterisk.org/t/duplicate-cdr-data-storing-issue/101330/3 "2024-03-05T13:32:26Z")

</div>

They are not the same!

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [March 5, 2024, 1:36pm UTC](https://community.asterisk.org/t/duplicate-cdr-data-storing-issue/101330/4 "2024-03-05T13:36:11Z")

</div>

Unique constraints are not there to work round this sort of problem. Although there isn’t enough information to understand this particular issue, if you are getting two records when you expect one, it is probably because you don’t understand how CDRs work.

Without the column names, dialplan, and CDR settings, I’m not sure why there are two records, but you should “fix” this by suppressing the second one, without understanding what is happening.

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [March 5, 2024, 1:51pm UTC](https://community.asterisk.org/t/duplicate-cdr-data-storing-issue/101330/5 "2024-03-05T13:51:07Z")

</div>

Based on the other post at [Not storing destination number in cdr table - #2 by jcolp](https://community.asterisk.org/t/not-storing-destination-number-in-cdr-table/101336/2) have you configured Asterisk to write CDRs into the database, but you’re also writing your own records in using func\_odbc?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [April 4, 2024, 1:51pm UTC](https://community.asterisk.org/t/duplicate-cdr-data-storing-issue/101330/6 "2024-04-04T13:51:50Z")

</div>

Closed on April 4, 2024, 1:51pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
