{"id":2177,"date":"2022-02-18T20:49:04","date_gmt":"2022-02-18T11:49:04","guid":{"rendered":"https:\/\/aiacademy.jp\/media\/?p=2177"},"modified":"2022-02-18T20:49:05","modified_gmt":"2022-02-18T11:49:05","slug":"invalidrequesterror-table-user-is-already-defined-for-this-metadata-instance","status":"publish","type":"post","link":"https:\/\/aiacademy.jp\/media\/?p=2177","title":{"rendered":"InvalidRequestError: Table &#8216;user&#8217; is already defined for this MetaData instance."},"content":{"rendered":"\n<div class=\"toc\">    <div id=\"toc_container\" class=\"sgb-toc--no-bullets js-smooth-scroll\" data-dialog-title=\"Table of Contents\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">  <li class=\"first\">    <span><\/span>    <ul class=\"menu_level_1\">      <li class=\"first last\">        <a href=\"#i-0\">InvalidRequestError: Table \u2018xxxxx\u2019 is already defined for this MetaData instance. \u3068\u306f<\/a>      <\/li>    <\/ul>  <\/li>  <li class=\"last\">    <a href=\"#i-1\">Python\u3092\u52b9\u7387\u3088\u304f\u5b66\u3076\u306b\u306f\uff1f<\/a>  <\/li><\/ul>\n      \n    <\/div><\/div><div class=\"toc\"><p><\/p>\n<\/div><h2 class=\"wp-block-heading\" id=\"i-0\">InvalidRequestError: Table \u2018xxxxx\u2019 is already defined for this MetaData instance. \u3068\u306f<\/h2>\n\n\n\n<p>SQLModel\u3092\u4f7f\u3063\u3066\u3044\u308b\u3068\u300cInvalidRequestError: Table \u2018<meta charset=\"utf-8\">xxxxx\u2019 is already defined for this MetaData instance.\u300d\u3068\u3044\u3063\u305f\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u30a8\u30e9\u30fc\u306f\u3001\u65e2\u306b\u5b58\u5728\u3059\u308b\u30c6\u30fc\u30d6\u30eb\u304c\u30e1\u30bf\u30c7\u30fc\u30bf\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u306b\u3001SQLModel\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30a8\u30e9\u30fc\u3092\u51fa\u529b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>InvalidRequestError: Table 'user' is already defined for this MetaData instance.  \nSpecify 'extend_existing=True' to redefine options and columns on an existing Table object.<\/code><\/pre>\n\n\n\n<p>\u3053\u306e\u5834\u5408\u3001User\u30e2\u30c7\u30eb\u5185\u306b\u3001<strong><strong>table_args<\/strong>&nbsp;= {\u2018extend_existing\u2019: True}<\/strong>\u306e\u8a18\u8f09\u3092\u3059\u308b\u3068\u30a8\u30e9\u30fc\u3092\u56de\u907f\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class User(SQLModel, table=True):\n    __table_args__ = {'extend_existing': True} \n    user_id: Optional[int] = Field(primary_key=True)\n    user_name: str<\/code><\/pre>\n\n\n\n<p>\u53c2\u8003\uff1a<a href=\"https:\/\/qiita.com\/AI_Academy\/items\/3f971088568cea2bb7b6\" rel=\"nofollow noopener\" target=\"_blank\">SQLModel\u3068\u306f \u301cSQLModel\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u30fbDB\u63a5\u7d9a\u30fb\u30c7\u30fc\u30bf\u8ffd\u52a0\u30fb\u30c7\u30fc\u30bf\u53d6\u5f97\u307e\u3067\u301c<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"i-1\">Python\u3092\u52b9\u7387\u3088\u304f\u5b66\u3076\u306b\u306f\uff1f<\/h1>\n\n\n\n<p>Python\u3092\u52b9\u7387\u3088\u304f\u5b66\u3076\u306b\u306f\u3001\u666e\u6bb5\u304b\u3089Python\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u73fe\u5f79\u306e\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30c6\u30a3\u30b9\u30c8\u3084\u6a5f\u68b0\u5b66\u7fd2\u30a8\u30f3\u30b8\u30cb\u30a2\u306b\u8cea\u554f\u3067\u304d\u308b\u74b0\u5883\u3067\u5b66\u3076\u3053\u3068\u3067\u3059\u3002<br>\u8cea\u554f\u3057\u653e\u984c\u304b\u3064\u3001\u4f53\u7cfb\u7684\u306b\u5b66\u3079\u308b\u52d5\u753b\u30b3\u30f3\u30c6\u30f3\u30c4\u3067\u30c7\u30fc\u30bf\u5206\u6790\u6280\u8853\u3092\u5b66\u3073\u305f\u3044\u65b9\u306f\u3001\u30aa\u30f3\u30e9\u30a4\u30f3\u3067\u597d\u304d\u306a\u6642\u9593\u306b\u52c9\u5f37\u3067\u304d\u308b<a href=\"https:\/\/aiacademy.jp\/bootcamp\" rel=\"noreferrer noopener\" target=\"_blank\">AI Academy Bootcamp<\/a>\u304c\u30aa\u30b9\u30b9\u30e1\u3067\u3059\u3002\u53d7\u8b1b\u6599\u3082\u696d\u754c\u6700\u5b89\u5024\u306e35,000\u5186\uff08\uff16\u30f6\u6708\u9593\u8cea\u554f\u3057\u653e\u984c\uff0b\u30aa\u30ea\u30b8\u30ca\u30eb\u306e\u52d5\u753b\u30b3\u30f3\u30c6\u30f3\u30c4\u3001\u30c6\u30ad\u30b9\u30c8\u30b3\u30f3\u30c6\u30f3\u30c4\u306e\u5229\u7528\u53ef\u80fd\uff09\u306a\u306e\u3067\u3001\u662f\u975e\u3054\u6d3b\u7528\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/aiacademy.jp\/bootcamp\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/qiita-user-contents.imgix.net\/https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F171715%2Fb4e1cc19-264c-7c56-28fb-1ceadb5c60ab.png?ixlib=rb-4.0.0&amp;auto=format&amp;gif-q=60&amp;q=75&amp;s=57ef2065c2b0849f483d6a61eeb0be8d\" alt=\"bootcamp_ad_72ppi.png\"><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6b21 InvalidRequestError: Table \u2018xxxxx\u2019 is already defined for this MetaData instance. \u3068\u306f Python\u3092\u52b9\u7387\u3088\u304f\u5b66\u3076\u306b\u306f\uff1f Inval &#8230; <\/p>\n","protected":false},"author":1,"featured_media":2179,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[165],"tags":[],"class_list":{"0":"post-2177","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-165"},"_links":{"self":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/2177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2177"}],"version-history":[{"count":1,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/2177\/revisions"}],"predecessor-version":[{"id":2178,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/2177\/revisions\/2178"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/media\/2179"}],"wp:attachment":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}