{"action":"created","issue":{"url":"https://api.github.com/repos/jinzhu/gorm/issues/593","labels_url":"https://api.github.com/repos/jinzhu/gorm/issues/593/labels{/name}","comments_url":"https://api.github.com/repos/jinzhu/gorm/issues/593/comments","events_url":"https://api.github.com/repos/jinzhu/gorm/issues/593/events","html_url":"https://github.com/jinzhu/gorm/issues/593","id":98675551,"number":593,"title":"AddForeignKey quotes reference table","user":{"login":"travisby","id":133506,"avatar_url":"https://avatars.githubusercontent.com/u/133506?v=3","gravatar_id":"","url":"https://api.github.com/users/travisby","html_url":"https://github.com/travisby","followers_url":"https://api.github.com/users/travisby/followers","following_url":"https://api.github.com/users/travisby/following{/other_user}","gists_url":"https://api.github.com/users/travisby/gists{/gist_id}","starred_url":"https://api.github.com/users/travisby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/travisby/subscriptions","organizations_url":"https://api.github.com/users/travisby/orgs","repos_url":"https://api.github.com/users/travisby/repos","events_url":"https://api.github.com/users/travisby/events{/privacy}","received_events_url":"https://api.github.com/users/travisby/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-03T05:34:42Z","updated_at":"2015-08-07T03:09:13Z","closed_at":null,"body":"Hello,\r\n\r\nI believe the AddForeignKey table has a small bug in it:\r\n\r\nMy golang code:\r\n\r\n```go\r\n db.Model(&A{}).AddForeignKey(\"b_id\", \"b(id)\", \"RESTRICT\", \"RESTRICT\")\r\n```\r\nGenerated Query:\r\n\r\n```sql\r\n ALTER TABLE \"a\" ADD CONSTRAINT \"a_b_id_foreign\" FOREIGN KEY (\"b_id\") REFERENCES \"b(id)\" ON DELETE RESTRICT ON UPDATE RESTRICT;\r\n```\r\n\r\nExpected query (runs in postgres):\r\n\r\n\r\n ```sql\r\nALTER TABLE \"a\" ADD CONSTRAINT \"a_b_id_foreign\" FOREIGN KEY (\"b_id\") REFERENCES b(id) ON DELETE RESTRICT ON UPDATE RESTRICT;\r\n```\r\n\r\n\r\nI *think* the solution is to not QuoteIfPossible on: https://github.com/jinzhu/gorm/blob/0def184b0ca6d0b4d4b772a18b909d35b6cb86a1/scope_private.go#L574 for dest\r\n\r\n\r\nHope this is helpful for others who use foreign keys :)  I was able to convert all but two of my foreign keys to struct tags (`sql:\"type uuid REFERENCES c(id)\"`), but I encountered this when two tables referred to one another (so I can't change creation ordering, heh)"},"comment":{"url":"https://api.github.com/repos/jinzhu/gorm/issues/comments/128575580","html_url":"https://github.com/jinzhu/gorm/issues/593#issuecomment-128575580","issue_url":"https://api.github.com/repos/jinzhu/gorm/issues/593","id":128575580,"user":{"login":"bertzzie","id":610268,"avatar_url":"https://avatars.githubusercontent.com/u/610268?v=3","gravatar_id":"","url":"https://api.github.com/users/bertzzie","html_url":"https://github.com/bertzzie","followers_url":"https://api.github.com/users/bertzzie/followers","following_url":"https://api.github.com/users/bertzzie/following{/other_user}","gists_url":"https://api.github.com/users/bertzzie/gists{/gist_id}","starred_url":"https://api.github.com/users/bertzzie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bertzzie/subscriptions","organizations_url":"https://api.github.com/users/bertzzie/orgs","repos_url":"https://api.github.com/users/bertzzie/repos","events_url":"https://api.github.com/users/bertzzie/events{/privacy}","received_events_url":"https://api.github.com/users/bertzzie/received_events","type":"User","site_admin":false},"created_at":"2015-08-07T03:09:13Z","updated_at":"2015-08-07T03:09:13Z","body":"Hello,\r\n\r\nI have the same problem in MariaDB (MySQL). Here's my database version for reference:\r\n\r\n    $ mysql --version\r\n    mysql  Ver 15.1 Distrib 10.0.19-MariaDB, for osx10.10 (x86_64) using readline 5.1\r\n\r\nThe rest of my problem is exactly the same with @travisby. Not sure about the solution though."}}