Grafana datasource error

Facing issue wrt mysql datasource :

configuration:

apiVersion: 1
datasources:
  - name: Prometheus
    type: prometheus
    access: proxy
    url: "http://localhost:9090/prometheus-production"
  - name: Loki
    type: loki
    access: proxy
    jsonData:
      maxLines: 1000    
    url: "http://localhost:3100"
  - name: abc
    type: mysql
    url: x.x.x.x:3306
    uid: P5B83B323F800A6FD
    user: grafanareader
    jsonData:
      maxOpenConns: 3 
      maxIdleConns: 3
      maxIdleConnsAuto: true 
      connMaxLifetime: 180 
    secureJsonData:
      password: xxxx
  - name: def
    type: mysql
    url: x.x.x.x:3306
    user: grafanareader
    jsonData:
      maxOpenConns: 3
      maxIdleConns: 3
      maxIdleConnsAuto: true
      connMaxLifetime: 180
    secureJsonData:
      password: xxx

error:

May 10 14:39:46 ip-172-31-62-33 grafana[117751]: logger=provisioning t=2024-05-10T14:39:46.759790681Z level=error msg="Failed to provision data sources" error="Datasource provisioning error: data source with the same uid already exists"

May 10 14:39:46 ip-172-31-62-33 grafana[117751]: Error: ✗ not healthy, 0 terminated, 1 failed: [invalid service state: 
Failed, expected: Running, failure: Datasource provisioning error: data source with the same uid already exists]

When i define a UID on datasource name def it works or else grafana fails with the error. Let me know what am i doing wrong. the UID on abc datasource is newly defined earlier it was present without a UID

welcome @singhsubham58

are you deleting these data sources before recreating them.

otherwise the static uid you have in your yaml will be a problem

see below in sample.yaml

deleteDatasources:
   - name: Graphite
     orgId: 1

it recreates fine with no error everytime

image