'schema file at path is invalid because no version is specified

I run my dbt command in a loop and save its contents to a .yml file. This works well and generates a schema in my .yml file accurately:

for file in models/l30_mart/*.sql; do
    table=$(basename "$file" .sql)
    dbt run-operation generate_model_yaml --args "{\"model_name\": \"$table\"}" > test.yml
done

However, in the example above, I am just saving the test.yml file in the root directory. When I try to save the file in another path for example models/l30_mart/test.yml, it doesn't work:

for file in models/l30_mart/*.sql; do
    table=$(basename "$file" .sql)
    dbt run-operation generate_model_yaml --args "{\"model_name\": \"$table\"}" > models/l30_mart/test.yml
done

In this case, when I open the test.ymlfile, I see this:

12:06:42  Running with dbt=1.0.1
12:06:43  Encountered an error:
Compilation Error
  The schema file at models/l30_mart/test.yml is invalid because no version is specified. Please consult the documentation for more information on schema.yml syntax:
  
  https://docs.getdbt.com/docs/schemayml-files

It's probably a syntax mistake. Do I need any quotes to specify the path? or brackets? Why can't I save the .yml file in the same folder? Similarly, something like this and try to save different files with the tablename, it also doesn't work:

for file in models/l30_mart/*.sql; do
    table=$(basename "$file" .sql)
    dbt run-operation generate_model_yaml --args "{\"model_name\": \"$table\"}" >  models/l30_mart/$table.yml
done

In this case, the files either have this output:

20:39:44  Running with dbt=1.0.1
20:39:45  Encountered an error:
Compilation Error
  The schema file at models/l30_mart/firsttable.yml is invalid because no version is specified. Please consult the documentation for more information on schema.yml syntax:
  
  https://docs.getdbt.com/docs/schemayml-files

or this (eg in the second tablename.yml file):

20:39:48  Running with dbt=1.0.1
20:39:49  Encountered an error:
Parsing Error
  Error reading dbt_4flow: l30_mart/firstablename.yml - Runtime Error
    Syntax error near line 2
    ------------------------------
    1  | 20:39:44  Running with dbt=1.0.1
    2  | 20:39:45  Encountered an error:
    3  | Compilation Error
    4  |   The schema file at models/l30_mart/firsttablename.yml is invalid because no version is specified. Please consult the documentation for more information on schema.yml syntax:
    5  |   
    
    Raw Error:
    ------------------------------
    mapping values are not allowed in this context
      in "<unicode string>", line 2, column 31

Note that the secondtablename.yml mentions the firsttablename.yml.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source