I have observed that the dbt overrides the existing table schema.
The below image shows the difference between table before and after running dbt code:
If see carefully the location_id column was REQUIRED but dbt overridden it and changed to NULLABLE. I want to ask you guys is there any way to avoid it? I want to preserve the original structure of table.
Also is there any option in dbt which will give me error if tried to change the datatype or constraint of column?
I think dbt always drops and creates again the tables referenced in a model unless you use the incremental materialization and have already a table with the same name as the model. Then you can work something there. On the other hand you can make tests that ensures that you have the required structure but i think dbt is not focused on that kind of scenarios, thats why it does not even supports foreign keys.
This is the link for a related question: