ActiveRecord::ConnectionAdapters::SQLite3Adapter 不支持跳过重复项
ActiveRecord::ConnectionAdapters::SQLite3Adapter does not support skipping duplicates
我在尝试对 Github 操作进行 运行 rspec 时遇到了这个问题。这是我的 github 操作流程。
name: Ruby
on:
push:
branches: [ master]
pull_request:
branches: [ master]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup System
run: |
sudo apt-get install sqlite3 libsqlite3-dev
- name: Set up Ruby 2.7.2
uses: actions/setup-ruby@v1
with:
ruby-version: 2.7.2
- name: Cache Ruby Gems
uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Bundle Install
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3 --without=production
- name: Setup DB
env:
RAILS_ENV: test
DISABLE_SPRING: 1
run: |
bin/rails db:setup db:migrate db:seed
- name: Run rspec
env:
RAILS_ENV: test
DISABLE_SPRING: 1
run: bundle exec rspec
- 我的代码正在调用
insert_all
。
- 我能够将错误追踪到 https://github.com/rails/rails/blob/main/activerecord/lib/active_record/insert_all.rb#L97
- 据我所知,它与插入的数据无关,而是与连接本身有关
- 出于某种原因,(sqlite3) 连接不支持跳过重复项
- 我在本地 macbook air 上没有收到此错误
tl;dr - 我使用的是旧版本的 SQLite3
好的,跟踪 rail 的代码,我发现它调用了 sqlite3 适配器
调用
指定 sqlite3 必须是 3.24.0 或更高版本。
同时,Github的ubuntu-当前最新(02-2021)使用Ubuntu 18作为“最新”。
并且 Ubuntu 上的 sqlite3 包默认安装 sqlite 3.22。来源:https://packages.ubuntu.com/search?keywords=sqlite3
所以改成runs-on: ubuntu-20.04
后我就不再遇到这个问题了!
我在尝试对 Github 操作进行 运行 rspec 时遇到了这个问题。这是我的 github 操作流程。
name: Ruby
on:
push:
branches: [ master]
pull_request:
branches: [ master]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup System
run: |
sudo apt-get install sqlite3 libsqlite3-dev
- name: Set up Ruby 2.7.2
uses: actions/setup-ruby@v1
with:
ruby-version: 2.7.2
- name: Cache Ruby Gems
uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Bundle Install
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3 --without=production
- name: Setup DB
env:
RAILS_ENV: test
DISABLE_SPRING: 1
run: |
bin/rails db:setup db:migrate db:seed
- name: Run rspec
env:
RAILS_ENV: test
DISABLE_SPRING: 1
run: bundle exec rspec
- 我的代码正在调用
insert_all
。 - 我能够将错误追踪到 https://github.com/rails/rails/blob/main/activerecord/lib/active_record/insert_all.rb#L97
- 据我所知,它与插入的数据无关,而是与连接本身有关
- 出于某种原因,(sqlite3) 连接不支持跳过重复项
- 我在本地 macbook air 上没有收到此错误
tl;dr - 我使用的是旧版本的 SQLite3
好的,跟踪 rail 的代码,我发现它调用了 sqlite3 适配器
调用
指定 sqlite3 必须是 3.24.0 或更高版本。
同时,Github的ubuntu-当前最新(02-2021)使用Ubuntu 18作为“最新”。
并且 Ubuntu 上的 sqlite3 包默认安装 sqlite 3.22。来源:https://packages.ubuntu.com/search?keywords=sqlite3
所以改成runs-on: ubuntu-20.04
后我就不再遇到这个问题了!