使用DBT,无法将数据从一个SQLite数据库插入到另一个SQLite数据库

问题描述 投票:0回答:1

作为我的第一个项目,我正在尝试在两个 SQLite 数据库之间移动数据。 我的第一个 SQLite 数据库中有三个表,其中包含很少的记录(1-2 条记录)

我正在尝试将这些记录复制到我的目标 SQLite 数据库中。 我能够运行我的模型,它们运行成功,并且它们还在我的第二个数据库中创建新的相同表。但没有数据被复制。我尝试了很多方法,但还是不行。

我的profiles.yaml文件,

local_sqlite_project:
  target: dev
  outputs:
    dev:
      type: sqlite
      threads: 1
      database: 'database'
      schema: 'main'
      schemas_and_paths:
        main: 'C:/Programming/Projects/dbt/target.db'
      schema_directory: 'file_path'
      #optional fields
#     extensions:
#       - "/path/to/sqlean/crypto.so"

# Add a new connection for your source SQLite file
  sources:
    dev:
      type: sqlite
      database: 'C:/Programming/Projects/dbt/dbt-tutorial/tutorial_project/source/source.db'
      schema: 'source'

我的 source.yaml 文件,

version: 2

sources:
  - name: sample_table_database
    database: 'source'  
    schema: 'main'
    tables:
      - name: first_table
      - name: second_table
      - name: third_table

我的first_model.sql文件(其他两个模型也一样,只是表名改了)



{{ config(materialized='table') }}

with source_data as (

    select ID, Name from {{ source('sample_table_database', 'first_table') }}

),

final as (
    select * from source_data
)

select * from final

不确定这是否有必要,但我的 dbt_project.yaml 文件也在这里共享,


# Name your project! Project names should contain only lowercase characters
# and underscores. A good package name should reflect your organization's
# name or the intended use of these models
name: 'tutorial_project'
version: '1.0.0'
config-version: 2

# This setting configures which "profile" dbt uses for this project.
profile: 'local_sqlite_project'

# These configurations specify where dbt should look for different types of files.
# The `model-paths` config, for example, states that models in this project can be
# found in the "models/" directory. You probably won't need to change these!
model-paths: ["models"]
analysis-paths: ["analyses"]
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

target-path: "target"  # directory which will store compiled SQL files
clean-targets:         # directories to be removed by `dbt clean`
  - "target"
  - "dbt_packages"


# Configuring models
# Full documentation: https://docs.getdbt.com/docs/configuring-models

# In this example config, we tell dbt to build all models in the example/
# directory as views. These settings can be overridden in the individual model
# files using the `{{ config(...) }}` macro.
models:
  tutorial_project:
    # Config indicated by + and applies to all files under models/example/
    example:
      +materialized: view

如果您想查看整个存储库,可以在这里这样做:https://github.com/hassanashas/dbt-tutorial

我还上传了SQLite文件,如果有人有兴趣可以查看一下,

https://drive.google.com/drive/folders/1PKdpffsPxAGg1f7yxNG3gHmKl6SsOFwr?usp=sharing

sqlite dbt
1个回答
0
投票

它不能算作解决方案,但我建议使用其他一些数据库,因为 sqlite 支持还不是那么强大。

© www.soinside.com 2019 - 2024. All rights reserved.