2018/01/05 17:19:27 INFO ▶ 0001 Using 'postgres' as 'driver'
2018/01/05 17:19:27 INFO ▶ 0002 Using 'postgres:@tcp(127.0.0.1:5432)/postgres' as 'conn'
2018/01/05 17:19:27 INFO ▶ 0003 Running all outstanding migrations
2018/01/05 17:19:27 FATAL ▶ 0004 Could not show migrations table: missing "=" after "postgres:@tcp(127.0.0.1:5432)/postgres" in connection info string"
因为他喵的不会!
所以执行了这句:
bee migrate -driver=postgres -conn=“postgres:@tcp(127.0.0.1:5432)/postgres”
然而这句是根据 beego
默认的mysql
的语法
然后看文档,找到了这句!
bee migrate -driver=postgres -conn=“postgres://postgres:postgres@127.0.0.1:5432/postgres”
然后还他喵的报错!
2018/01/05 17:21:29 INFO ▶ 0001 Using 'postgres' as 'driver'
2018/01/05 17:21:29 INFO ▶ 0002 Using 'postgres://postgres:postgres@127.0.0.1:5432/postgres' as 'conn'
2018/01/05 17:21:29 INFO ▶ 0003 Running all outstanding migrations
2018/01/05 17:21:29 FATAL ▶ 0004 Could not show migrations table: pq: SSL is not enabled on the server
找到了解决办法:
bee migrate -driver=postgres -conn=“postgres://postgres:postgres@127.0.0.1:5432/postgres?sslmode=disable”
不会又报错了
应该是账号密码不对
2018/01/05 17:34:00 INFO ▶ 0001 Using 'postgres' as 'driver'
2018/01/05 17:34:00 INFO ▶ 0002 Using 'postgres://postgres:postgres@127.0.0.1:5432/postgres?sslmode=disable' as 'conn'
2018/01/05 17:34:00 INFO ▶ 0003 Running all outstanding migrations
2018/01/05 17:34:00 FATAL ▶ 0004 Could not show migrations table: pq: password authentication failed for user "postgres"
后来看到这个…
db, err := sql.Open(“postgres”, “postgres://username:password@localhost/db_name?sslmode=disable”)
原来我把密码写成了 postgres
,我的密码是 123456
bee migrate -driver=postgres -conn=“postgres://postgres:123456@127.0.0.1:5432/postgres?sslmode=disable”
然后执行 还是报错
2018/01/05 17:43:24 INFO ▶ 0001 Using 'postgres' as 'driver'
2018/01/05 17:43:24 INFO ▶ 0002 Using 'postgres://postgres:123456@127.0.0.1:5432/postgres?sslmode=disable' as 'conn'
2018/01/05 17:43:24 INFO ▶ 0003 Running all outstanding migrations
2018/01/05 17:43:28 INFO ▶ 0004 |> 2018/01/05 17:43:26 [I] start upgrade User_20180105_163508
2018/01/05 17:43:28 INFO ▶ 0005 |> 2018/01/05 17:43:26 [I] exec sql: CREATE TABLE user(id serial primary key,name TEXT NOT NULL,email TEXT NOT NULL,password TEXT NOT NULL)
2018/01/05 17:43:28 INFO ▶ 0006 |> 2018/01/05 17:43:26 [E] execute error: pq: syntax error at or near "user"
2018/01/05 17:43:28 ERROR ▶ 0007 Could not run migration binary: exit status 2
哈哈,这个问题就麻烦了!我查了好久没解决之法!
然后我把表的名字改成了 users
他喵的! 成功了!
2018/01/05 18:04:46 INFO ▶ 0001 Using 'postgres' as 'driver'
2018/01/05 18:04:46 INFO ▶ 0002 Using 'postgres://postgres:123456@127.0.0.1:5432/postgres?sslmode=disable' as 'conn'
2018/01/05 18:04:46 INFO ▶ 0003 Running all outstanding migrations
2018/01/05 18:04:50 INFO ▶ 0004 |> 2018/01/05 18:04:48 [I] start upgrade User_20180105_163508
2018/01/05 18:04:50 INFO ▶ 0005 |> 2018/01/05 18:04:48 [I] exec sql: CREATE TABLE users(id serial primary key,name TEXT NOT NULL,email TEXT NOT NULL,password TEXT NOT NULL)
2018/01/05 18:04:50 INFO ▶ 0006 |> 2018/01/05 18:04:48 [I] end upgrade: User_20180105_163508
2018/01/05 18:04:50 INFO ▶ 0007 |> 2018/01/05 18:04:48 [I] total success upgrade: 1 migration
2018/01/05 18:04:50 SUCCESS ▶ 0008 Migration successful!
然后在软件里看到了我要的表!
哎!不会玩只能瞎鸡巴摸索了!(希望一段时间后的我看到这,不要觉得自己是个傻x就行)
本站(PHP --> Golang)已重构,代码开源
当你能力不能满足你的野心的时候,你就该沉下心来学习