2017-04-08 4 views
1

IMDBPY 5.1を使用してimdbデータをmysqlデータベースにロードしようとしました。 しかし、私はいつも最後に次の問題に遭遇します。私は完全な主キー+スキーマ内の外部キー制約を持つ必要があります。可能性のある原因が原因であるというヒントを誰かに教えてもらえますか?imdbpyを使用してimdbデータをmysqlにロードするときに外部キーを追加する

1)は、すべての必要なパッケージをインストールし、次のように私が使用し

building database indexes (this may take a while) 
# TIME createIndexes() : 38min, 6sec (wall) 0min, 0sec (user) 0min, 0sec (system) 
adding foreign keys (this may take a while) 
ERROR caught exception creating a foreign key: Cannot add or update a child row: a foreign key constraint fails (`imdb`.`#sql-65bf_d`, CONSTRAINT `title_episode_of_id_exists` FOREIGN KEY (`episode_of_id`) REFERENCES `title` (`id`)) 
ERROR caught exception creating a foreign key: Cannot add or update a child row: a foreign key constraint fails (`imdb`.`#sql-65bf_e`, CONSTRAINT `aka_title_movie_id_exists` FOREIGN KEY (`movie_id`) REFERENCES `title` (`id`)) 
ERROR caught exception creating a foreign key: Cannot add or update a child row: a foreign key constraint fails (`imdb`.`#sql-65bf_e`, CONSTRAINT `cast_info_movie_id_exists` FOREIGN KEY (`movie_id`) REFERENCES `title` (`id`)) 
ERROR caught exception creating a foreign key: Cannot add or update a child row: a foreign key constraint fails (`imdb`.`#sql-65bf_e`, CONSTRAINT `complete_cast_movie_id_exists` FOREIGN KEY (`movie_id`) REFERENCES `title` (`id`)) 
ERROR caught exception creating a foreign key: Cannot add or update a child row: a foreign key constraint fails (`imdb`.`#sql-65bf_e`, CONSTRAINT `movie_keyword_movie_id_exists` FOREIGN KEY (`movie_id`) REFERENCES `title` (`id`)) 
ERROR caught exception creating a foreign key: Cannot add or update a child row: a foreign key constraint fails (`imdb`.`#sql-65bf_e`, CONSTRAINT `movie_link_movie_id_exists` FOREIGN KEY (`movie_id`) REFERENCES `title` (`id`)) 
ERROR caught exception creating a foreign key: Cannot add or update a child row: a foreign key constraint fails (`imdb`.`#sql-65bf_e`, CONSTRAINT `movie_info_movie_id_exists` FOREIGN KEY (`movie_id`) REFERENCES `title` (`id`)) 
ERROR caught exception creating a foreign key: Cannot add or update a child row: a foreign key constraint fails (`imdb`.`#sql-65bf_e`, CONSTRAINT `movie_info_idx_movie_id_exists` FOREIGN KEY (`movie_id`) REFERENCES `title` (`id`)) 
ERROR caught exception creating a foreign key: Cannot add or update a child row: a foreign key constraint fails (`imdb`.`#sql-65bf_e`, CONSTRAINT `movie_companies_movie_id_exists` FOREIGN KEY (`movie_id`) REFERENCES `title` (`id`)) 
# TIME createForeignKeys() : 655min, 16sec (wall) 0min, 0sec (user) 0min, 0sec (system) 
RESTORING imdbIDs values for movies... WARNING: unable to restore imdbIDs using the temporary table (falling back to dbm): missing "title_extract" table (ok if this is the first run) 
WARNING: unable to restore imdbIDs (ok if this is the first run) 
RESTORING imdbIDs values for people... WARNING: unable to restore imdbIDs using the temporary table (falling back to dbm): missing "name_extract" table (ok if this is the first run) 
WARNING: unable to restore imdbIDs (ok if this is the first run) 
RESTORING imdbIDs values for characters... WARNING: unable to restore imdbIDs using the temporary table (falling back to dbm): missing "char_name_extract" table (ok if this is the first run) 
WARNING: unable to restore imdbIDs (ok if this is the first run) 
RESTORING imdbIDs values for companies... WARNING: unable to restore imdbIDs using the temporary table (falling back to dbm): missing "company_name_extract" table (ok if this is the first run) 
WARNING: unable to restore imdbIDs (ok if this is the first run) 

コマンドです。

sudo apt-get install -y gcc python python-dev libssl-dev libxml2-dev libxslt1-dev zlib1g-dev python-setuptools python-pip 
easy_install -U SQLObject 
pip install MySQL-python 

2)IMDBPYをインストールします。

3)mysqlでデータベース "imdb"を作成し、すべての特権をパスワード "password"で "user"に付与します。

CREATE DATABASE imdb; 
GRANT ALL PRIVILEGES ON imdb.* TO 'user'@'localhost' IDENTIFIED BY 'password'; 
FLUSH PRIVILEGES; 

4)すべてのIMDBデータをダウンロードします。

mkdir [imdb_data_directory] 
cd [imdb_data_directory] 
wget -r --accept="*.gz" --no-directories --no-host-directories --level 1 ftp://ftp.fu-berlin.de/pub/misc/movies/database/ 

5)IMDBデータをmysqlにロードします。

cd [IMDBPY_parent_directory]/IMDbPY-5.1/bin 
python imdbpy2sql.py -d [imdb_data_directory] -u 
'mysql://user:[email protected]/imdb' 

私の設定は次のとおりです。

  • のpython:2.7
  • のMySQL:5.7
  • のUbuntu 16.04

また、私はMacOSの10.12で試してみました+ 5.7 +のpython 2.7をMySQLと同じ問題がありました。代わりにSQLOBJECTのSQLAlchemyのを使用してダヴィデの提案に

私は、次のコマンドを使用して、SQLAlchemyのを試してみました:

python imdbpy2sql.py -d [imdb_file_directory] -o sqlalchemy -u 'mysql://user:[email protected]/imdb?charset=utf8&local_infile=1' 

私は、次のエラーを得ました。

Traceback (most recent call last): 
    File "imdbpy2sql.py", line 538, in <module> 
    conn = setConnection(URI, DB_TABLES) 
    File "/Library/Python/2.7/site-packages/IMDbPY-5.1-py2.7-macosx-10.12-intel.egg/imdb/parser/sql/alchemyadapter.py", line 489, in setConnection 
    engine = create_engine(uri, **params) 
    File "/Library/Python/2.7/site-packages/sqlalchemy/engine/__init__.py", line 387, in create_engine 
    return strategy.create(*args, **kwargs) 
    File "/Library/Python/2.7/site-packages/sqlalchemy/engine/strategies.py", line 160, in create 
    engineclass.__name__)) 
TypeError: Invalid argument(s) 'local_infile' sent to create_engine(), using configuration MySQLDialect_mysqldb/QueuePool/Engine. Please check that the keyword arguments are appropriate for this combination of components. 

私はバージョン1.1.8のsqlalchemyを使用していました。私はsqlalchemyバージョン0.5に切り替えたときに同じエラーが発生しました。私は0.4をSQLAlchemyのに切り替えたときに、私はこのエラーを受け取っ:

Traceback (most recent call last): 
    File "imdbpy2sql.py", line 323, in <module> 
    from imdb.parser.sql.alchemyadapter import getDBTables, setConnection 
    File "/Library/Python/2.7/site-packages/IMDbPY-5.1-py2.7-macosx-10.12-intel.egg/imdb/parser/sql/alchemyadapter.py", line 54, in <module> 
    UNICODECOL: UnicodeText, 
NameError: name 'UnicodeText' is not defined 

私が間違って「local_infile」を指定しましたか?

答えて

1

おそらくコード内にバグがあります。

回避策として、SQLObjectではなくSQLAlchemyを使用してください。 imdbpy2sql.pyのコマンドラインオプションに "-o sqlalchemy"(引用符なし)を追加してインストールしてみてください。

関連する問題