2016-03-09 103 views
0

我遇到了問題,我無法理解在其他地方找到解決方案。事情是,當我試圖加載架構與使用PostgreSQL加載模式之後的Rails語法錯誤

load "#{Rails.root}/db/sctructure.sql" 

錯誤出現。 postgresql版本是9.5.1,pg gem是0.8.1。 正如我所能理解的,pg gem無法識別轉儲文件的註釋。 你有沒有遇到類似的東西?

SyntaxError: /Users/user/Documents/workspace/app/db/structure.sql:2: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '(' 
-- PostgreSQL database dump 
        ^
/Users/user/Documents/workspace/app/db/structure.sql:5: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '(' 
-- Dumped from database version 9.5.1 
      ^
/Users/user/Documents/workspace/app/db/structure.sql:5: unexpected fraction part after numeric literal 
-- Dumped from database version 9.5.1 
           ^
/Users/user/Documents/workspace/app/db/structure.sql:6: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '(' 
-- Dumped by pg_dump version 9.5.1 
      ^
/Users/user/Documents/workspace/app/db/structure.sql:6: unexpected fraction part after numeric literal 
-- Dumped by pg_dump version 9.5.1 
           ^
/Users/user/Documents/workspace/app/db/structure.sql:17: syntax error, unexpected tLABEL 
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: - 
     ^
/Users/user/Documents/workspace/app/db/structure.sql:17: syntax error, unexpected ':', expecting end-of-input 
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: - 

的structure.sql文件的一部分:

-- PostgreSQL database dump 
-- 

-- Dumped from database version 9.5.1 
-- Dumped by pg_dump version 9.5.1 

SET statement_timeout = 0; 
SET lock_timeout = 0; 
SET client_encoding = 'UTF8'; 
SET standard_conforming_strings = on; 
SET check_function_bodies = false; 
SET client_min_messages = warning; 
SET row_security = off; 

-- 
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: - 
-- 

CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; 


-- 
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: - 
-- 

COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; 


SET search_path = public, pg_catalog; 

SET default_tablespace = ''; 

SET default_with_oids = false; 

-- 
-- Name: accounts; Type: TABLE; Schema: public; Owner: - 
-- 

CREATE TABLE accounts (
    id integer NOT NULL, 
    name character varying, 
    logo character varying, 
    website character varying, 
    subdomain character varying, 
    active boolean, 
    created_at timestamp without time zone NOT NULL, 
    updated_at timestamp without time zone NOT NULL 
); 


-- 
-- Name: accounts_id_seq; Type: SEQUENCE; Schema: public; Owner: - 
-- 

CREATE SEQUENCE accounts_id_seq 
    START WITH 1 
    INCREMENT BY 1 
    NO MINVALUE 
    NO MAXVALUE 
    CACHE 1; 


-- 
-- Name: accounts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - 
-- 

ALTER SEQUENCE accounts_id_seq OWNED BY accounts.id; 


-- 
-- Name: addresses; Type: TABLE; Schema: public; Owner: - 
-- 

CREATE TABLE addresses (
    id integer NOT NULL, 
    location_id integer, 
    location_type character varying, 
    street character varying, 
    number character varying, 
    zip character varying, 
    city character varying, 
    country character varying, 
    created_at timestamp without time zone NOT NULL, 
    updated_at timestamp without time zone NOT NULL 
); 


-- 
-- Name: addresses_id_seq; Type: SEQUENCE; Schema: public; Owner: - 
-- 

CREATE SEQUENCE addresses_id_seq 
    START WITH 1 
    INCREMENT BY 1 
    NO MINVALUE 
    NO MAXVALUE 
    CACHE 1; 


-- 
-- Name: addresses_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - 
-- 

ALTER SEQUENCE addresses_id_seq OWNED BY addresses.id; 


-- 
-- Name: administrators; Type: TABLE; Schema: public; Owner: - 
-- 

CREATE TABLE administrators (
    id integer NOT NULL, 
    created_at timestamp without time zone NOT NULL, 
    updated_at timestamp without time zone NOT NULL 
); 


-- 
-- Name: administrators_id_seq; Type: SEQUENCE; Schema: public; Owner: - 
-- 

CREATE SEQUENCE administrators_id_seq 
    START WITH 1 
    INCREMENT BY 1 
    NO MINVALUE 
    NO MAXVALUE 
    CACHE 1; 


-- 
-- Name: administrators_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - 
-- 

ALTER SEQUENCE administrators_id_seq OWNED BY administrators.id; 


-- 
-- Name: agreements; Type: TABLE; Schema: public; Owner: - 
-- 

CREATE TABLE agreements (
    id integer NOT NULL, 
    employee_id integer, 
    client_id integer, 
    contract_id integer, 
    created_at timestamp without time zone NOT NULL, 
    updated_at timestamp without time zone NOT NULL 
); 


-- 
-- Name: agreements_id_seq; Type: SEQUENCE; Schema: public; Owner: - 
-- 

CREATE SEQUENCE agreements_id_seq 
    START WITH 1 
    INCREMENT BY 1 
    NO MINVALUE 
    NO MAXVALUE 
    CACHE 1; 


-- 
-- Name: agreements_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - 
-- 

ALTER SEQUENCE agreements_id_seq OWNED BY agreements.id; 


-- 
-- Name: api_authorizations; Type: TABLE; Schema: public; Owner: - 
-- 

CREATE TABLE api_authorizations (
    id integer NOT NULL, 
    authorizable_id integer, 
    authorizable_type character varying, 
    client_id character varying, 
    client_secret character varying, 
    access_token character varying, 
    access_expires_at timestamp without time zone, 
    download_token character varying, 
    token_type character varying, 
    scope character varying, 
    refresh_token character varying, 
    refresh_expires_at timestamp without time zone, 
    created_at timestamp without time zone NOT NULL, 
    updated_at timestamp without time zone NOT NULL 
); 


-- 
-- Name: api_authorizations_id_seq; Type: SEQUENCE; Schema: public; Owner: - 
-- 

CREATE SEQUENCE api_authorizations_id_seq 
    START WITH 1 
    INCREMENT BY 1 
    NO MINVALUE 
    NO MAXVALUE 
    CACHE 1; 


-- 
-- Name: api_authorizations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - 
-- 

ALTER SEQUENCE api_authorizations_id_seq OWNED BY api_authorizations.id; 


-- 
-- Name: billings; Type: TABLE; Schema: public; Owner: - 
-- 

CREATE TABLE billings (
    id integer NOT NULL, 
    user_id integer, 
    bank_account_number character varying, 
    bic character varying, 
    created_at timestamp without time zone NOT NULL, 
    updated_at timestamp without time zone NOT NULL 
); 


-- 
-- Name: billings_id_seq; Type: SEQUENCE; Schema: public; Owner: - 
-- 

CREATE SEQUENCE billings_id_seq 
    START WITH 1 
    INCREMENT BY 1 
    NO MINVALUE 
    NO MAXVALUE 
    CACHE 1; 


-- 
-- Name: billings_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - 
-- 

ALTER SEQUENCE billings_id_seq OWNED BY billings.id; 


-- 
-- Name: clients; Type: TABLE; Schema: public; Owner: - 
-- 

CREATE TABLE clients (
    id integer NOT NULL, 
    external_id character varying, 
    url_digest character varying, 
    employee_id integer, 
    created_at timestamp without time zone NOT NULL, 
    updated_at timestamp without time zone NOT NULL 
); 


-- 
-- Name: clients_id_seq; Type: SEQUENCE; Schema: public; Owner: - 
-- 

CREATE SEQUENCE clients_id_seq 
    START WITH 1 
    INCREMENT BY 1 
    NO MINVALUE 
    NO MAXVALUE 
    CACHE 1; 


-- 
-- Name: clients_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - 
-- 

ALTER SEQUENCE clients_id_seq OWNED BY clients.id; 


-- 
-- Name: companies; Type: TABLE; Schema: public; Owner: - 
-- 

CREATE TABLE companies (
    id integer NOT NULL, 
    name character varying, 
    revenue numeric(15,2), 
    employee_number integer, 
    sector character varying, 
    foundation_date date, 
    tax_number character varying, 
    vat_id character varying, 
    total_salaries numeric(15,2), 
    client_id integer, 
    created_at timestamp without time zone NOT NULL, 
    updated_at timestamp without time zone NOT NULL 
); 


-- 
-- Name: companies_id_seq; Type: SEQUENCE; Schema: public; Owner: - 
-- 

CREATE SEQUENCE companies_id_seq 
    START WITH 1 
    INCREMENT BY 1 
    NO MINVALUE 
    NO MAXVALUE 
    CACHE 1; 


-- 
-- Name: companies_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - 
-- 

ALTER SEQUENCE companies_id_seq OWNED BY companies.id; 


-- 
-- Name: contacts; Type: TABLE; Schema: public; Owner: - 
-- 

CREATE TABLE contacts (
    id integer NOT NULL, 
    honorific integer, 
    title character varying, 
    first_name character varying, 
    last_name character varying, 
    birth_date date, 
    telephone character varying, 
    user_id integer, 
    created_at timestamp without time zone NOT NULL, 
    updated_at timestamp without time zone NOT NULL 
); 


-- 
-- Name: contacts_id_seq; Type: SEQUENCE; Schema: public; Owner: - 
-- 

CREATE SEQUENCE contacts_id_seq 
    START WITH 1 
    INCREMENT BY 1 
    NO MINVALUE 
    NO MAXVALUE 
    CACHE 1; 


-- 
-- Name: contacts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - 
-- 

ALTER SEQUENCE contacts_id_seq OWNED BY contacts.id; 


-- 
-- Name: contract_categories; Type: TABLE; Schema: public; Owner: - 
-- 

CREATE TABLE contract_categories (
    id integer NOT NULL, 
    name character varying, 
    contract_group_id integer, 
    created_at timestamp without time zone NOT NULL, 
    updated_at timestamp without time zone NOT NULL 
); 


-- 
-- Name: contract_categories_id_seq; Type: SEQUENCE; Schema: public; Owner: - 
-- 

CREATE SEQUENCE contract_categories_id_seq 
    START WITH 1 
    INCREMENT BY 1 
    NO MINVALUE 
    NO MAXVALUE 
    CACHE 1; 


-- 
-- Name: contract_categories_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - 
-- 

ALTER SEQUENCE contract_categories_id_seq OWNED BY contract_categories.id; 


-- 
-- Name: contract_groups; Type: TABLE; Schema: public; Owner: - 
-- 

CREATE TABLE contract_groups (
    id integer NOT NULL, 
    name character varying, 
    created_at timestamp without time zone NOT NULL, 
    updated_at timestamp without time zone NOT NULL 
); 


-- 
-- Name: contract_groups_id_seq; Type: SEQUENCE; Schema: public; Owner: - 
-- 

CREATE SEQUENCE contract_groups_id_seq 
    START WITH 1 
    INCREMENT BY 1 
    NO MINVALUE 
    NO MAXVALUE 
    CACHE 1; 


-- 
-- Name: contract_groups_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - 
-- 

回答

1

您看到這個錯誤,因爲你無法load SQL文件。 load僅用於加載紅寶石文件。

+0

有沒有什麼辦法可以在我的模型中加載db/structure.sql文件? – marinoszak

+0

您是否嘗試過'rake db:schema:load'? –

+0

我已經嘗試過,但我認爲db:schema:load不加載structure.sql文件。它僅適用於schema.rb,還是我錯了?在我寫的應用程序中,我有多個租戶,當我創建新租戶時,我想更改search_path並加載structure.sql文件。 – marinoszak