The problem I’m having
I have a table [Site] that is a slowly changing dimension so I am creating a snapshot for this table. When I run “dbt snapshot” the first time the snapshot table is created. Any subsequent run results in the following error:
(‘23000’, “[23000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot insert explicit value for identity column in table ‘site_snapshot’ when IDENTITY_INSERT is set to OFF. (544) (SQLExecDirectW); [23000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Database name ‘DirectoryDW’ ignored, referencing object in tempdb. (2701)”)
I am using dbt sql server and the [Site] table does have an auto-increment identity.
What I’ve already tried
I looked up the issue and only saw an unresolved post on this forum.
I tried setting IDENTITY_INSERT to on for the snapshot table but I’m still getting the same error.
Here is the snapshot code that runs:
{% snapshot site_snapshot %}
{{
config(
target_database='DirectoryDW',
target_schema='dbo',
unique_key='siteid',
strategy='check',
check_cols=['isactive', 'tier']
)
}}
select [siteid]
,[sitename]
,[homeurl]
,[directoryurl]
,[sitetype]
,[fullsitename]
,[sitenamesuffix]
,publisherid
,[isactive]
,[tier]
,[createdate]
from {{ source('mb', 'Site') }}
{% endsnapshot %}
Thanks,
Matt