Django从sqlite3切换到Postgresql问题
【腾讯云】亏本大甩卖,服务器4核16G 1年370元(带宽12M,系统盘120GB SSD盘,月流量2000GB)!!!!!!
云产品 配置 价格
服务器 1核2G,带宽5M,系统盘50GB SSD盘,月流量500GB 38元/年
MySQL 1核1G 19元/年
服务器 16核32G,带宽18M,系统盘250GB SSD盘,月流量5000GB 1197元/年
点我进入腾讯云,查看更多详情

I've recently changed the database server on my project from sqlite3 to Postgresql and I have a few questions that I hope will give an answer to my issues.

  1. I understand that switching from sqlite to Postgres implies that I create the new database and the tables inside it, right? I've done that but I haven't seen any new files created in my project to show me that the database I've made is visible. (Btw, I've changed the database name in settings.py)

  2. I probably should mention that I'm working in a virtual environment and I would like to know if that affects my references in any way. I've tried to import the tables in Django to try and count the number of records in a table but I get the error: "No module named psdemo". (psdemo is my database name and i'm trying to import the table with:

    from ps.psdemo import Product
    

    where ps is my application, psdemo is my database and Product the table in the database.

In conclusion I'm trying to get access to my database and tables but I can't manage to find them. I repeat, there is no new database file in my project or in my virtual environment (I've searched thoroughly) but if I use a terminal connection I can connect to my virtual environment and change directories to get to the application folder then if I connect to the Postgresql server I can create the database, the tables and can Insert into them, make queries etc, but I cannot access them from the Django code.

#0

I understand that switching from sqlite to Postgres implies that I create the new database and the tables inside it, right? I've done that but I haven't seen any new files created in my project to show me that the database I've made is visible. (Btw, I've changed the database name in settings.py)

Database files are not created in the project directory with postgresql. They are created in the database server data directory (like /var/lib/postgres it depends on the distribution). You should generally query it through a PostgreSQL client that connects to the PostgreSQL server rather than messing with the files directly.

You can for example run command:

manage.py dbshell

#1

I understand that switching from sqlite to Postgres implies that I create the new database and the tables inside it, right? I've done that but I haven't seen any new files created in my project to show me that the database I've made is visible. (Btw, I've changed the database name in settings.py)

All you have to do with postgres is create the database. Not the tables. Django will create the tables, and anything else it thinks are useful, once you call syncdb.

You won't have any new files in your project like you did in sqlite. If you want to view your database, you should download and install pgadminIII (which I would recommend in any event)

I probably should mention that I'm working in a virtual environment and I would like to know if that affects my references in any way. I've tried to import the tables in Django to try and count the number of records in a table but I get the error: "No module named psdemo". (psdemo is my database name and i'm trying to import the table with:

Here, you import models via normal python syntax and it then references your tables. Each model should represent a single table. You define your models first, and then call

python manage.py syncdb

In conclusion I'm trying to get access to my database and tables but I can't manage to find them.

See above, but you should definitely read about postgres installation from the postgres docs, and read the psycopg2 docs as well as the Django docs for setting up a postgres database.

#2

As to your first issue, see @jpic's answer.

On your second issue, your database is not a package, and you do not import models from your database. If you were able to import your models correctly before you made any changes, change your import statements back to how they were.

推荐文章

为什么下面的代码失败

为什么下面的代码失败

推荐文章

C#在类之间传递消息

C#在类之间传递消息

推荐文章

MySQL InnoDB:“reads/s”的单位是什么?

MySQL InnoDB:“reads/s”的单位是什么?

推荐文章

如何在C语言中传递函数中的二维数组(矩阵)?

如何在C语言中传递函数中的二维数组(矩阵)?

推荐文章

一个应用,多个品牌

一个应用,多个品牌

推荐文章

WIndows窗体窗口加载方法未完成

WIndows窗体窗口加载方法未完成

推荐文章

异步任务花费了荒谬的时间

异步任务花费了荒谬的时间

推荐文章

javascript onclick事件处理程序运行不正常

javascript onclick事件处理程序运行不正常

推荐文章

在python中有没有通过正则表达式找到子字符串索引的方法?

在python中有没有通过正则表达式找到子字符串索引的方法?

推荐文章

Robotium测试失败,错误为:junit.framework.AssertionFailedError:无法单击视图!

Robotium测试失败,错误为:junit.framework.AssertionFailedError:无法单击视图!

推荐文章

将position列添加到MySQL的子表中,以便使用Hibernate映射到Java列表

将position列添加到MySQL的子表中,以便使用Hibernate映射到Java列表

推荐文章

一般协变误差

一般协变误差

推荐文章

Delphi中的参数传递静态字节数组

Delphi中的参数传递静态字节数组

推荐文章

如何在VB6应用程序中调用.NET创建的DLL?

如何在VB6应用程序中调用.NET创建的DLL?

推荐文章

无法在InstanceIn中使用GetLocalResourceObject

无法在InstanceIn中使用GetLocalResourceObject

推荐文章

枚举正则表达式匹配名称/值

枚举正则表达式匹配名称/值