使用 Faker 库填充 Django 数据库我的代码,当我编译时它没有显示任何错误,但不在管理页面中填充假数据

发布于 2025-01-17 20:26:27 字数 627 浏览 4 评论 0原文

这是我的第一个文件,它是填充数据库的脚本:{'fake_data.py')当我运行python face_data.py时,它显示了“填充了facky_data填充了填充的facky_data!”

此文件是'module.py

但是当我运行服务器时,假数据不在管理页面中。

This is my first file which is the script for populating the database: ('fake_data.py') when I run python fake_data.py it showing "populating fake_data populating complated!"
enter image description here

This file is 'module.py
enter image description here

But when I am running server the fake data is not in admin page.
enter image description here

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

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

发布评论

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

评论(1

記柔刀 2025-01-24 20:26:27

注意

我不明白你为什么使用faker,但如果你想用随机数据填充数据库,那么在

fake_data.py

# Import your libraries here
import random

# define your here
def main():
    # Call populate
    print("Populating random data begins ...")
    populate(20)
    print("Populating random data ends ...")


# random tasks
todos = ["foo", "bar", "bazz"]


def add_todo():
    # Create and save records in database
    q = TODO.objects.create(name=random.choice(todos))
    return q


def populate(N=5):
    for counter in range(N):
        entry = add_todo()

# call your main
if __name__ == "__main__":
    main()
  • 中请注意,如果你不使用q和代码中其他位置的 entry ,然后将它们都删除。

Note

I don't understand why are you using faker but if you want to populate your database with random data then in

fake_data.py

# Import your libraries here
import random

# define your here
def main():
    # Call populate
    print("Populating random data begins ...")
    populate(20)
    print("Populating random data ends ...")


# random tasks
todos = ["foo", "bar", "bazz"]


def add_todo():
    # Create and save records in database
    q = TODO.objects.create(name=random.choice(todos))
    return q


def populate(N=5):
    for counter in range(N):
        entry = add_todo()

# call your main
if __name__ == "__main__":
    main()
  • Note that if you don't use q and entry else where in your code, then remove both of them.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文