如何更改云中的数据库本地(django)

发布于 2025-01-25 10:10:00 字数 155 浏览 2 评论 0原文

我在Django Framework中写了一个项目,并使用本地数据库SQLite,现在我想将其上传到云中,以便其他与我一起工作的人可以访问数据库IE,即创建用户时,我的共同存在将存在该用户。工人。

也许有人有关于如何执行此操作的指南,而无需修改数据库,以便我不必修改代码的其余部分?

I wrote a project in django framework and I use the local DataBase SQLite, and I now want to upload it to the cloud so other people who work with me can access DataBase i.e. when I create a user then that user will exist with my co-workers.

Maybe someone has a guide on how to do this without modifying the DataBase so that I do not have to modify the rest of the code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

活泼老夫 2025-02-01 10:10:00

好吧,我找到了答案,
您应该使用djongo 您应该做的是连接django和mongodb

您可以从在这里

我建议您遵循我的设定。

  1. 转到Monogodb网站 - > clickhere 并创建免费帐户。
  2. 创建新的群集
  3. ,然后您将在部署下的左侧按下数据库中,您将倒向此页面。
  4. 按Connect buttom


例如!!!

mongodb+srv://<username>:<password>@<atlas cluster>/<myFirstDatabase>?retryWrites=true&w=majority

复制此链接并执行下一个setps:

  • 返回您的终端并安装此软件包:pip install djongo
  • 并打开设置。py
  • 将日期库更改为这样:
 数据库= {
        '默认': {
            '引擎':'djongo',
            “名称”:'your db-name',
            '客户': {
                '主机':'Mongodb+Srv://&lt; username&gt;:&lt; password&gt;@qut&lt; atlascluster&gt;/&lt; myfirstdatabase&gt;?retrywrites&gt;?
            }  
        }
}
 
  • 在“主机”粘贴您从monogodb网站复制的链接。
  • 在“名称”中写下您的数据库名称。

现在我们已经拥有Django项目(和应用程序),可以使用命令在MongoDB中创建集合:

python manage.py makemigrations <app-name>

python manage.py migrate

如果您获得错误,例如' django.db.utils.databaseerror'
您应该做的是:
它删除了您创建的应用程序中的迁移文件夹中的所有文件,然后再运行上面的命令。

Ok i found the answer,
what you should do is Connect Django and MongoDB Using Djongo

you can read from here

I RECOMMEND TO FOLLOW MY SETPS.

  1. go to monogodb site -> clickHere and create free account.
  2. create new cluster
  3. then you will reverse to this page if no in the left side press DataBase under DEPLOYMENT and then you get. enter image description here
  4. press on Connect buttom enter image description here
  5. choose "Connect your application" and then choose python and the last version

after all this you will have this link:
for example!!!

mongodb+srv://<username>:<password>@<atlas cluster>/<myFirstDatabase>?retryWrites=true&w=majority

copy this link and do the next setps:

  • go back to your terminal and install this package: pip install djongo
  • and open settings.py
  • change your DATEBASE to like this:
DATABASES = {
        'default': {
            'ENGINE': 'djongo',
            'NAME': 'your-db-name',
            'CLIENT': {
                'host': 'mongodb+srv://<username>:<password>@<atlascluster>/<myFirstDatabase>?retryWrites=true&w=majority'
            }  
        }
}
  • in 'host' paste the link you copy from monogodb site.
  • in 'NAME' write your name of the database.

Now that we have the Django project (and app), you can create the collections in MongoDB using the commands:

python manage.py makemigrations <app-name>

python manage.py migrate

if you get error like 'django.db.utils.databaseerror'
what you should to do is:
It deletes all the files that are in the migrations folder that are in the apps you have created and after that run again the command above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文