brobin / django-seed Goto Github PK
View Code? Open in Web Editor NEW:seedling: Seed your Django database with fake data
License: MIT License
:seedling: Seed your Django database with fake data
License: MIT License
Command:
seeder = Seed.seeder()
Error:
ImportError: The ``fake-factory`` package is now called ``Faker``.
Please update your requirements.
I want to use same email for my generated code.
seeder.add_entity(User, 10, {
'username': lambda x: seeder.faker.name(),
'email': lambda x: seeder.faker.email(),
'password': lambda x: seeder.faker.password(),
})
In this code, I want to use same email that is in email field for username. Is there any way I can do tha?
DataError: value too long for type character varying(50)
Seeding should take into account the max_length of the field.
If the django settings uses time zones, DateTimeFields throw the following Runtimewarning:
RuntimeWarning:
DateTimeField StoryPost.published received a
naive datetime (1978-07-06 22:37:20)
while time zone support is active.
RuntimeWarning)
Possible solution:
when populating date time fields, check if timezone is active via settings.py, and if it is,
set the field value via timezone.now()
"--seeder" arg not working in management command
this command:
./manage.py seed location --number=10 --seeder "Address.hours" "None"
gives me:
manage.py seed: error: unrecognized arguments: --seeder Address.hours {}
Django==3.2.4
Python 3.8.10
I have a DateTimeField
with auto_add_now=True
.
When I run
seeder.add_entity(Item, 15, {'date': lambda x: seeder.faker.date_time_between(start_date='-1y'),})
seeder.execute()
(or without defining the date
generator) I only get Items with the date equal to the time I run the code.
I believe this is incorrect behaviour, please correct me if I'm wrong.
https://github.com/Brobin/django-seed/blob/master/django_seed/seeder.py#L30-L36
This pulls a random value from inserted values; it needs to be one to one.
Using Django 1.7.7 and Python 2.7.5 I did a pip install and the management command doesn't get installed. I even tried pip installing using git+git://github.com/Brobin/django-seed.git
and that didn't work either.
Hi,
Using django_seed
with Faker 3.0.0 causes the following exception:
TypeError: Calling `.seed()` on instances is deprecated. Use the class method `Faker.seed()` instead.
It can be traced up to line 35, faker
method:
File "/Users/User/Projects/Django/MyProject/TestApp/management/commands/generate.py", line 13, in generate
seeder = Seed.seeder()
File "/Users/User/Projects/Django/MyProject/lib/python3.7/site-packages/django_seed/__init__.py", line 42, in seeder
faker = cls.fakers.get(code, None) or cls.faker(codename=code)
File "/Users/User/Projects/Django/MyProject/lib/python3.7/site-packages/django_seed/__init__.py", line 35, in faker
cls.fakers[code].seed(random.randint(1, 10000))
File "/Users/User/Projects/Django/MyProject/lib/python3.7/site-packages/faker/proxy.py", line 79, in __getattribute__
I believe the issue may lie in the fact that since Faker v2.0.4, calling seed
on Faker
instances has been disabled.
Check https://faker.readthedocs.io/en/master/fakerclass.html#breaking-change for the rationale and fix.
The moment I got this exception I was using:
Faker 3.0.0
django-seed 0.1.9
python 3.7
Thanks,
Eddie
I have the following model in one of my apps:
class Currency(models.Model):
abbrev = models.CharField(max_length=3, unique=True)
As the CharField
is currently implemented, I am having problems getting a word that has a maximum length of 3
Django now supports postgres fields like ArrayField, JSONField, HStoreField etc.
https://docs.djangoproject.com/en/1.9/ref/contrib/postgres/fields/
seed
management command as well as seeder.add_entity
fails since they are not been detected with FieldTypeGuesser
.
It would be great to have this support at least at the add_entity
level.
attempting to run my code as:
from django_seed import Seed
seeder = Seed.seeder()
from report_builder_demo.demo_models.models import Waiter, Restaurant,Foo,Place,FooExclude,Bar
seeder.add_entity(Waiter, 15)
seeder.add_entity(Restaurant, 10)
seeder.add_entity(Place, 5)
seeder.add_entity(Bar, 10)
seeder.add_entity(FooExclude, 5)
seeder.add_entity(Foo, 10)
inserted_pks = seeder.execute()
django_seed.exceptions.SeederException: Field demo_models.Waiter.name cannot be null
the model is as follows:
class Waiter(models.Model):
restaurant = models.ForeignKey(Restaurant)
name = models.CharField(max_length=50)
def __str__(self):
return "%s the waiter at %s" % (self.name, self.restaurant)
In cases where a model wants a relationship with another model through one-to-one, many-to-one, or many-to-many, currently, it can only use objects that were created in the current execute. It can look in the database and find other objects that match, but those might not have been created by django-seed. It would be helpful to have a flag that allowed django-seed to make relationships with existing data when seeding. Otherwise it should only use objects that are stored in the inserted list from the current django-seed session.
This will also require looking into how the "inserted" list is stored over multiple executes.
Hi Brobin.
I opened the ticket regarding this line
In my project I use a field 'Point' from GeoDjango and I faced AttributeError.
I can make a PR for this field, but I am sure, that time will come and someone will face AttributeError again.
I see few possible ways how AttributeError can be solved (at least how to add some flexibility) and would like to discuss it with you in order to avoid work which will not be merged.
Solution # 1:
Ignore fields if field has "null=True"
Solution # 2:
If dict has 'some_new_field' (field which is not covered by django-seed), AttributeError should not be raised, because dict already has info what type of faker must be used.
seeder.add_entity(Player, 10, {
'score': lambda x: random.randint(0,1000),
'some_new_field': lambda x: seeder.faker.some_item(),
})
Solution # 3:
Just to add an optional flag, something like 'ignore_unknown_fields=True'
seeder.add_entity(Player, 10, {
'score': lambda x: random.randint(0,1000),
'some_new_field': lambda x: seeder.faker.some_item(),
},
ignore_unknown_fields=True
)
and let django-seed to work just with known fields.
Solution # 4:
Implement all solutions :)
What is acceptable? Maybe you have your own thoughts?
Thanks.
File "/home/vagrant/.local/lib/python2.7/site-packages/django_seed/seeder.py", line 149, in execute entity = self.entities[klass].execute(using, inserted_entities) File "/home/vagrant/.local/lib/python2.7/site-packages/django_seed/seeder.py", line 92, in execute for field, field_format in self.field_formatters.items() AttributeError: 'str' object has no attribute 'isoformat'
This happens when running seeder.execute() upon ajax call.
I made a file called seed.py
in the root of my Django project (next to manage.py) so I can use Seed.seeder()
.
When I run the command like this:
$ python seed.py
I get the following error:
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
I cannot seem to get it to create data for any application I have so far.
python manage.py seed booking --number=15
Error message:
cls.fakers[code].seed_instance(random.randint(1, 10000))
AttributeError: 'Generator' object has no attribute 'seed_instance'
Using python3.8
Add these new fields. There should be faker methods for most of these.
Param number
has default value but it's not obvious from help text.
Connected issue.
#104
We are using the latest version, but Array Field is still not properly supported.
pip list
django-seed 0.3.1
No matter what form the model is modified, Array Field is not properly recognized.
models.py
1. blablaField = ArrayField(models.TextField(), blank=False, size=6, null=True)
2. blablaField = ArrayField(
models.TextField(),
blank=True,
size=6,
null=True,
)
3. blablaField = ArrayField(
models.TextField(
max_length=100,
null=True,
),
blank=True,
size=6,
null=True,
)
4. blablaField = ArrayField(
models.TextField(
max_length=100,
null=True,
blank=True,
),
blank=True,
size=6,
null=True,
)
When I deleted the field only right, it worked.
models.py
~~~
(delete blablaField)
~~~
I think an error occurs when the model is verified in the add_entity process. This is because an error occurred even if a field value was not added within add_entity.
seed_blablas.py
class Command:
~~
def handle(self, *args, **options):
total = options.get("total")
seeder = Seed.seeder()
seeder.add_entity(
=========== here ===============
blablaModels,
=========== here ===============
total,
{
"name": lambda x: "name" + seeder.faker.first_name(),
"code": lambda x: "code" + seeder.faker.first_name(),
},
)
seeder.execute()
Error
Creating server_django_run ... done
PostgreSQL is available
Traceback (most recent call last):
File "manage.py", line 31, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/app/server/blablaModels/management/commands/seed_blablas.py", line 16, in handle
seeder.add_entity(
File "/usr/local/lib/python3.8/site-packages/django_seed/seeder.py", line 132, in add_entity
model.field_formatters = model.guess_field_formatters(self.faker)
File "/usr/local/lib/python3.8/site-packages/django_seed/seeder.py", line 60, in guess_field_formatters
formatter = field_type_guesser.guess_format(field)
File "/usr/local/lib/python3.8/site-packages/django_seed/guessers.py", line 109, in guess_format
raise AttributeError(field)
AttributeError: blabla.blablaModels.blablaField
Since it is an internal code of the company, it has been modified to blabla. Let me know if there's another problem!
Even though I'm not using Postgres for Django (just yet), the use of ArrayFields requires me to have it installed.
Traceback (most recent call last):
File "/home/forest/Documents/git/megagame-controller/django/manage.py", line 22, in <module>
main()
File "/home/forest/Documents/git/megagame-controller/django/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/home/forest/Documents/git/megagame-controller/django/player/management/commands/seed.py", line 27, in handle
seeder = Seed.seeder(locale="en_CA")
File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django_seed/__init__.py", line 43, in seeder
from django_seed import seeder
File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django_seed/seeder.py", line 6, in <module>
from django_seed.guessers import NameGuesser, FieldTypeGuesser
File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django_seed/guessers.py", line 5, in <module>
from django.contrib.postgres.fields import ArrayField
File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django/contrib/postgres/fields/__init__.py", line 1, in <module>
from .array import * # NOQA
File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django/contrib/postgres/fields/array.py", line 3, in <module>
from django.contrib.postgres import lookups
File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django/contrib/postgres/lookups.py", line 4, in <module>
from .search import SearchVector, SearchVectorExact, SearchVectorField
File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django/contrib/postgres/search.py", line 1, in <module>
import psycopg2
ModuleNotFoundError: No module named 'psycopg2'
I'm attempting to use this to populate an app and I get the error:
ImportError: No module named management.commands.seed
I've attempted install from pip and from github
Is this maintained? Pull Requests are left open without comment.
django-seed does not fill in this field, and instead raises an error
saying the field cannot be null.
Command used: (output does not change regardless of optional parameters)
seeder.add_entity(LifeXIdea, 1, {
'modified': timezone.now,
})
Model field in lifeX.models.LifeXIdea
:
modified = models.DateTimeField(blank=True,)
Traceback:
Traceback (most recent call last):
File "/Volumes/Data/CODE/harshp.com/source/sitedata/tests.py", line 57, in setUp
insertedPKs = seeder.execute()
File "/Volumes/Data/CODE/harshp.com/lib/python2.7/site-packages/django_seed/seeder.py", line 133, in execute
entity = self.entities[klass].execute(using, inserted_entities)
File "/Volumes/Data/CODE/harshp.com/lib/python2.7/site-packages/django_seed/seeder.py", line 71, in execute
setattr(obj, field, format(inserted_entities))
File "/Volumes/Data/CODE/harshp.com/lib/python2.7/site-packages/django_seed/seeder.py", line 39, in build_relation
raise SeederException(message)
SeederException: Field lifeX.LifeXIdea.modified cannot be null
First time using Django Seed. Great project, congrats! I'm trying understand this issue:
$ ./manage.py seed_responses --number 15
Traceback (most recent call last):
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/fields/__init__.py", line 1774, in get_prep_value
return int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'dict'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "./manage.py", line 22, in <module>
main()
File "./manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/usr/src/secret/api/core/management/commands/seed_responses.py", line 36, in handle
seeder.execute()
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django_seed/seeder.py", line 157, in execute
entity = self.entities[klass].execute(using, inserted_entities)
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django_seed/seeder.py", line 101, in execute
obj = manager.create(**faker_data)
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/query.py", line 447, in create
obj.save(force_insert=True, using=self.db)
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/base.py", line 753, in save
self.save_base(using=using, force_insert=force_insert,
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/base.py", line 790, in save_base
updated = self._save_table(
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/base.py", line 895, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/base.py", line 933, in _do_insert
return manager._insert(
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/query.py", line 1249, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1396, in execute_sql
for sql, params in self.as_sql():
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1339, in as_sql
value_rows = [
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1340, in <listcomp>
[self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1340, in <listcomp>
[self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1281, in prepare_value
value = field.get_db_prep_save(value, connection=self.connection)
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/fields/related.py", line 971, in get_db_prep_save
return self.target_field.get_db_prep_save(value, connection=connection)
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/fields/__init__.py", line 823, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/fields/__init__.py", line 2388, in get_db_prep_value
value = self.get_prep_value(value)
File "/usr/src/secret/api/.venv/lib/python3.8/site-packages/django/db/models/fields/__init__.py", line 1776, in get_prep_value
raise e.__class__(
TypeError: Field 'id' expected a number but got {<class 'core.models.Response'>: []}.
Can help me? My model:
from django.core.management import BaseCommand
from django_seed import Seed
from core.models import Application, Campaign, Response
# import uuid
import random
from django.contrib.auth import get_user_model
class Command(BaseCommand):
help = 'This command creates many responses.'
def add_arguments(self, parser):
parser.add_argument(
'--number', default=1, help='How many responses do you want to create?'
)
def handle(self, *args, **options):
number = int(options.get('number', 1))
seeder = Seed.seeder()
applications = Application.objects.all()
campaigns = Campaign.objects.all()
seeder.add_entity(Response, number, {
# 'id': lambda x: uuid.uuid4(),
'completed': False,
'application': lambda x: random.choice(applications),
'userId': 1,
'campaign': lambda x: random.choice(campaigns),
'deleted_by': get_user_model(),
})
seeder.execute()
self.stdout.write(self.style.SUCCESS('{} responses created.'.format(number)))
Django==3.1.1
psycopg2-binary==2.8.6
djangorestframework==3.11.1
django-cors-headers==3.5.0
django-extensions==3.0.9
django-colorfield==0.3.2
django-environ==0.4.5
django-q==1.3.3
django-seed==0.2.2
uWSGI==2.0.19.1
django-extensions==3.0.9
uWSGI==2.0.19.1
python-ulid==1.0.2
sentry-sdk==0.19.4
redis==3.5.3
whitenoise==5.2.0
the seeder throws an error when it tries to seed this field:
phones = ArrayField(base_field=models.CharField( _("Phone Number"), max_length=50, validators=[phone_validator], unique=True, ))
isn't it supported?
Cannot handle MPTTModel; I think it's choking on any ForiegnKey to self. WIll confirm
I'm getting this error while trying to seed this model:
class Contact(models.Model):
telephone = models.CharField(max_length=50, null=True, blank=True)
mobile_phone = models.CharField(max_length=50, null=True, blank=True)
address = models.CharField(max_length=50, blank=True, null=True)
postal_code = models.CharField(max_length=50, null=True, blank=True)
email_address = models.EmailField(max_length=100, blank=False, null=False)
website = models.URLField(null=True, blank=True)
I suspect this is due to the address field, since faker.address()
may return an address longer than 50 chars.
When I try to install django-seed by running pip install -r requirements.txt
I get the following stack trace complaining about django-seed's setup.py not being able to import django. As you can see from the earlier output of the command, Django 1.8 is installed in the VE before django-seed is requested so I am not sure why the import fails.
---- Begin output of "bash" "/tmp/chef-script20150528-12312-12cu373" ----
STDOUT: Collecting Django>=1.8 (from -r /srv/ads/django/mk_web_core/current/requirements.Linux.txt (line 1))
Using cached Django-1.8.2-py2.py3-none-any.whl
Collecting psycopg2 (from -r /srv/ads/django/mk_web_core/current/requirements.Linux.txt (line 2))
Using cached psycopg2-2.6.tar.gz
Collecting django-suit (from -r /srv/ads/django/mk_web_core/current/requirements.Linux.txt (line 3))
Using cached django-suit-0.2.13.tar.gz
Collecting django-suit-ckeditor (from -r /srv/ads/django/mk_web_core/current/requirements.Linux.txt (line 4))
Using cached django-suit-ckeditor-0.0.2.tar.gz
Collecting gunicorn (from -r /srv/ads/django/mk_web_core/current/requirements.Linux.txt (line 5))
Using cached gunicorn-19.3.0-py2.py3-none-any.whl
Collecting pytz (from -r /srv/ads/django/mk_web_core/current/requirements.Linux.txt (line 6))
Using cached pytz-2015.4-py2.py3-none-any.whl
Collecting django-seed (from -r /srv/ads/django/mk_web_core/current/requirements.Linux.txt (line 7))
Using cached django-seed-0.1.2.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/tmp/pip-build-56d4f_m7/django-seed/setup.py", line 6, in <module>
version=__import__('django_seed').__version__,
File "/tmp/pip-build-56d4f_m7/django-seed/django_seed/__init__.py", line 2, in <module>
from django.conf import settings
ImportError: No module named 'django'
----------------------------------------
STDERR: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-56d4f_m7/django-seed
---- End output of "bash" "/tmp/chef-script20150528-12312-12cu373" ----
Ran "bash" "/tmp/chef-script20150528-12312-12cu373" returned 1
[2015-05-28T18:17:35+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully \
(exit code 1)
Logging into the same server, removing and recreating the ve, then installing from a pip command works fine:
(ve)$ pip install -r current/requirements.Linux.txt
pip install -r current/requirements.Linux.txt
Collecting Django>=1.8 (from -r current/requirements.Linux.txt (line 1))
Downloading Django-1.8.2-py2.py3-none-any.whl (6.2MB)
100% |████████████████████████████████| 6.2MB 126kB/s
^[[?25hCollecting psycopg2 (from -r current/requirements.Linux.txt (line 2))
Downloading psycopg2-2.6.tar.gz (367kB)
100% |████████████████████████████████| 368kB 1.7MB/s
^[[?25hCollecting django-suit (from -r current/requirements.Linux.txt (line 3))
Downloading django-suit-0.2.13.tar.gz (1.4MB)
100% |████████████████████████████████| 1.4MB 494kB/s
^[[?25hCollecting django-suit-ckeditor (from -r current/requirements.Linux.txt (line 4))
Downloading django-suit-ckeditor-0.0.2.tar.gz (686kB)
100% |████████████████████████████████| 688kB 1.1MB/s
^[[?25hCollecting gunicorn (from -r current/requirements.Linux.txt (line 5))
Downloading gunicorn-19.3.0-py2.py3-none-any.whl (110kB)
100% |████████████████████████████████| 110kB 4.6MB/s
^[[?25hCollecting pytz (from -r current/requirements.Linux.txt (line 6))
Downloading pytz-2015.4-py2.py3-none-any.whl (475kB)
100% |████████████████████████████████| 475kB 1.5MB/s
^[[?25hCollecting django-seed (from -r current/requirements.Linux.txt (line 7))
Collecting fake-factory>=0.5.0 (from django-seed->-r current/requirements.Linux.txt (line 7))
Building wheels for collected packages: psycopg2, django-suit, django-suit-ckeditor
Running setup.py bdist_wheel for psycopg2
Stored in directory: /home/gunicorn/.cache/pip/wheels/ab/0c/9d/317c0ed55c67242a8f2de674f843a608eda4b8a45c73ff01a9
Running setup.py bdist_wheel for django-suit
Stored in directory: /home/gunicorn/.cache/pip/wheels/cc/b6/75/9f5a95b7dc77583e563bfaccd73d07c1b9a8826bc0ca102667
Running setup.py bdist_wheel for django-suit-ckeditor
Stored in directory: /home/gunicorn/.cache/pip/wheels/28/46/2d/d952b70457a04354e8759073422f362a37e2c8117c62e1c45b
Successfully built psycopg2 django-suit django-suit-ckeditor
Installing collected packages: Django, psycopg2, django-suit, django-suit-ckeditor, gunicorn, pytz, fake-factory, djang
o-seed
Successfully installed Django-1.8.2 django-seed-0.1.2 django-suit-0.2.13 django-suit-ckeditor-0.0.2 fake-factory-0.5.1
gunicorn-19.3.0 psycopg2-2.6 pytz-2015.4
django_seed.exceptions.SeederException: Field product.QASection.content_type cannot be null
I just installed this lib and tried to create some fake data with the command provided by the documentation. But it fails with the following error:
python manage.py seed member --number=15
usage: manage.py seed [-h] [--version] [-v {0,1,2,3}] [--settings SETTINGS]
[--pythonpath PYTHONPATH] [--traceback] [--no-color]
app_label [app_label ...]
manage.py seed: error: unrecognized arguments: --number=15
Any idea what's going on?
django-seed Version: 0.1.6
Django: 1.10.2
Python: 3.5
I use UUIDField
as primary key for my models:
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
If I run seed
manage command it can't handle it and tries to create all records with the same uuid.
I got this exception
django_seed.exceptions.SeederException: Field myapp.MyModel.description cannot be null
everytime I run command:
python manage.py seed myapp
model definition
class MyModel(models.Model):
description = models.TextField('description', blank=True, null=True, default=None)
Any ideas? Thank you.
(using Django 1.8.3, Python 2.7.6, django-seed 0.1.3)
This is just a list of features that I should look into
pip3 install django-seed==0.2.2
Collecting django-seed
Using cached django-seed-0.2.2.tar.gz (12 kB)
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ne1krphb/django-seed/setup.py'"'"'; file='"'"'/tmp/pip-install-ne1krphb/django-seed/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-w9lxjy_t
cwd: /tmp/pip-install-ne1krphb/django-seed/
Complete output (7 lines):
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-install-ne1krphb/django-seed/setup.py", line 59, in
long_description=open('README.rst', 'r').read(),
File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3008: ordinal not in range(128)
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
python --version
Python 3.6.9
pip --version
pip 20.1 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)
manage.py seed auth
results in:
(venv)vagrant@vagrant-ubuntu-trusty-64:/vagrant$ python manage.py seed auth
Seeding 10 Permissions
Seeding 10 Groups
Seeding 10 Users
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 449, in handle
app_output = self.handle_app_config(app_config, **options)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django_seed/management/commands/seed.py", line 38, in handle_app_config
pks = seeder.execute()
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django_seed/seeder.py", line 133, in execute
entity = self.entities[klass].execute(using, inserted_entities)
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django_seed/seeder.py", line 71, in execute
setattr(obj, field, format(inserted_entities))
File "/home/vagrant/venv/local/lib/python2.7/site-packages/django_seed/seeder.py", line 39, in build_relation
raise SeederException(message)
django_seed.exceptions.SeederException: Field auth.Permission.codename cannot be null
(venv)vagrant@vagrant-ubuntu-trusty-64:/vagrant$
django 1.7.8
django_seed from git
Gives error when installing with pip:
ERROR: Command errored out with exit status 1:
command: 'c:\users\pc\pycharmprojects\django\vuedjango\venv\scripts\python.exe' -c 'import sys, setuptools, token
ize; sys.argv[0] = '"'"'C:\Users\PC\AppData\Local\Temp\pip-install-wpmmq_lk\django-seed\setup.py'"'"'; _file
_='"'"'C:\Users\PC\AppData\Local\Temp\pip-install-wpmmq_lk\django-seed\setup.py'"'"';f=getattr(tokenize, '"'"'
open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file,
'"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\PC\AppData\Local\Temp\pip-pip-egg-info-npo8uz2r'
cwd: C:\Users\PC\AppData\Local\Temp\pip-install-wpmmq_lk\django-seed
Complete output (7 lines):
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\PC\AppData\Local\Temp\pip-install-wpmmq_lk\django-seed\setup.py", line 59, in
long_description=open('README.rst', 'r').read(),
File "C:\Users\PC\AppData\Local\Programs\Python\Python38-32\lib\encodings\cp1257.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0xa5 in position 3015: character maps to
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Is there an example of how django-seed
can generate fake users to populate test database?
I have a django app called trainers
in which I implement login / logout API's, and inside this app I created a serializer for the User model imported from django.contrib.auth.models
When I ran python manage.py seed trainers --number=15
, I get django_seed.exceptions.SeederException: No classed found. Did you add entities to the Seeder?
Is there an entity step I'm missing to be able to generate data for Django's User model? If so, how would one go about adding this entity to the Seeder?
django-seed seems to ignore the fields in the base model when I try to seed them. It seeds the fields on the inherited model correctly but when it tries to save the model it throws an error because the fields on the base model are not filled.
I'll take a look at this later and see if I can fix this.
It might be useful to add Proxy models to the tests as well.
Hi, have a way to ignore duplicates?
Without use IntegrityError
.
try:
# code
except django.db.utils.IntegrityError:
pass
django.db.utils.IntegrityError: duplicate key value violates unique constraint "core_response_application_id_campaign_id_userId_86e1adfd_uniq"
Thanks!
requirements.txt or README does not mention the following packages which are required to run tests:
This causes errors when executing python runtests.py
When can the latest version (0.3.0) be installed through pip? The 0.2.2 version is still being installed.
I want to automate arrayfield, but it is impossible.
models.py
rules = ArrayField(models.TextField(), blank=False, size=6, null=True)
seed.py
def handle(self, *args, **options):
total = options.get("total")
seeder = Seed.seeder()
seeder.add_entity(
model~,
total,
{
~,
"rules": '["blabla"],',
=or> "rules": None,
=or> "rules": '{"blabla"},',
=or> "rules": "[]",
=or> "rules": [],
~,
},
)
seeder.execute()
Error
File "/usr/local/lib/python3.8/site-packages/django_seed/guessers.py", line 109, in guess_format
raise AttributeError(field)
AttributeError: models.class.rules
All cases corresponding to =or>
have been put in, but the same error occurs. I think raise error occurs because it is not filtered from if
at guessers.py.
I know that this is because it is an old version. Can you tell me how I can handle this with hardcoding?
I already checked the link below.
#36
The management command file management/commands/seed.py
suppressed warning for non-timezone aware date times which is not documented or can simply be undesirable in outputs. Instead, the warnings should be shown and / or timezone support should be added for faked date time fields.
from core.management.commands.custom_command import CustomCommand
from django.contrib.admin.utils import flatten
from django_seed import Seed
from random import choice, randint
from rooms.models import Room, RoomType, Photo, Amenity, Facility, HouseRule
from users.models import User
class Command(CustomCommand):
help = "Automatically create rooms"
def add_arguments(self, parser):
parser.add_argument("--number", default=1, help="Number of rooms to create")
def handle(self, *args, **options):
try:
number = int(options.get("number"))
self.stdout.write(self.style.SUCCESS("■ START CREATE ROOMS"))
users = User.objects.all()
room_types = RoomType.objects.all()
amenities = Amenity.objects.all()
facilities = Facility.objects.all()
house_rules = HouseRule.objects.all()
seeder = Seed.seeder()
seeder.add_entity(
Room,
number,
{
"name": seeder.faker.address(),
"host": choice(users),
"room_type": choice(room_types),
"price": randint(1, 300),
"guests": randint(1, 10),
"beds": randint(1, 5),
"bedrooms": randint(1, 5),
"baths": randint(1, 5),
},
)
clean_pk_list = flatten(list(seeder.execute().values()))
for idx, pk in enumerate(clean_pk_list):
room = Room.objects.get(pk=pk)
BOOLEAN = [True, False]
self.progress_bar(
idx + 1, number, prefix="■ PROGRESS", suffix="Complete", length=40
)
for i in range(randint(7, 27)):
Photo.objects.create(
caption=seeder.faker.sentence(),
file=f"room_photos/{randint(1, 31)}.webp",
room=room,
)
for amenity in amenities:
if choice(BOOLEAN):
room.amenities.add(amenity)
for facility in facilities:
if choice(BOOLEAN):
room.facilities.add(facility)
for house_rule in house_rules:
if choice(BOOLEAN):
room.house_rules.add(house_rule)
self.stdout.write(self.style.SUCCESS("■ SUCCESS CREATE ALL ROOMS!"))
except Exception as e:
self.stdout.write(self.style.ERROR(f"■ {e}"))
self.stdout.write(self.style.ERROR("■ FAIL CREATE ROOMS"))
$ python manage.py seed_rooms --number 10
■ START CREATE ROOMS
■ PROGRESS |████████████████████████████████████████| 100.0% Complete
■ SUCCESS CREATE ALL ROOMS!
OS : Window10
django = "==2.2.10"
django-seed = "*"
python_version = "3.7"
"django-seed": {
"hashes": [
"sha256:5cdda71dcd51b2e7340e4aec9035d99d7014409a4b11adddbdff17d814968221"
],
"index": "pypi",
"version": "==0.2.2"
},
Why does this happen?
All fields are same created by add_entity
method.
Or skip it, to avoid
AttributeError: app.SomeJSONData.json
I have a models file with the following field:
active = models.BooleanField(default=True, blank=True)
I also have also overriden the save method in this model as follows
def save(self):
if datetime.date.today() > self.endDate:
self.active = False
if self.id:
self.lastModified = datetime.datetime.now()
else:
pass
super(Project, self).save()
When I run python manage.py seed app_name --number=5
, I am always getting the following exception:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/kevin/.virtualenvs/aims/lib/python3.4/site-packages/django/core/ma
nagement/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/kevin/.virtualenvs/aims/lib/python3.4/site-packages/django/core/ma
nagement/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/kevin/.virtualenvs/aims/lib/python3.4/site-packages/django/core/ma
nagement/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/kevin/.virtualenvs/aims/lib/python3.4/site-packages/django/core/ma
nagement/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/home/kevin/.virtualenvs/aims/lib/python3.4/site-packages/django/core/ma
nagement/base.py", line 565, in handle
app_output = self.handle_app_config(app_config, **options)
File "/home/kevin/.virtualenvs/aims/lib/python3.4/site-packages/django_seed/ma
nagement/commands/seed.py", line 38, in handle_app_config
pks = seeder.execute()
File "/home/kevin/.virtualenvs/aims/lib/python3.4/site-packages/django_seed/se
eder.py", line 133, in execute
entity = self.entities[klass].execute(using, inserted_entities)
File "/home/kevin/.virtualenvs/aims/lib/python3.4/site-packages/django_seed/se
eder.py", line 71, in execute
setattr(obj, field, format(inserted_entities))
File "/home/kevin/.virtualenvs/aims/lib/python3.4/site-packages/django_seed/se
eder.py", line 39, in build_relation
raise SeederException(message)
django_seed.exceptions.SeederException: Field data_entry.Project.active cannot b
e null
Please help me figure out what may be the cause of this Exception.
I am using Django 1.8.1 and Python 3.4.3
Thanks in advance.
This is my test case. After seeder.excute() some models, I cannot create this model instance without set created_at field, because turn_off_auto_add update filed attr but not recovery.
class MyModel(models.Model):
name = models.CharField(max_length=255)
created_at = models.DateTimeField(auto_now=False, auto_now_add=True)
class MyTest(TestCase):
def test(self):
faker = fake
seeder = Seeder(faker)
MyModel.objects.create(name='1') # no error
seeder.add_entity(MyModel, 1)
MyModel.objects.create(name='2') # no error
seeder.execute()
# error: django.db.utils.IntegrityError: NOT NULL constraint failed: django_seed_mymodel.created_at
MyModel.objects.create(name='3')
code in ModelSeeker
def turn_off_auto_add(model):
for field in model._meta.fields:
if getattr(field, "auto_now", False):
field.auto_now = False
if getattr(field, "auto_now_add", False):
field.auto_now_add = False
manager = self.model.objects.db_manager(using=using)
turn_off_auto_add(manager.model) # only turn off but not recovery
faker_data = {
field: format_field(field_format, inserted_entities)
for field, field_format in self.field_formatters.items()
}
# max length restriction check
for data_field in faker_data:
field = self.model._meta.get_field(data_field)
if field.max_length and isinstance(faker_data[data_field], str):
faker_data[data_field] = faker_data[data_field][:field.max_length]
obj = manager.create(**faker_data)
for field, list in self.many_relations.items():
list = list(inserted_entities)
if list:
for related_obj in list:
getattr(obj, field).add(related_obj)
return obj.pk
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.