When I run django tests I get the error:
IntegrityError: Problem installing fixture ... ContentType matching
query does not exist.: (auth.group:pk=2) field_value was
'[u'add_corsmodel', u'corsheaders', u'corsmodel']'
I get the fixtures by doing
python manage.py dumpdata --natural-foreign --exclude=contenttypes --exclude=auth.Permission
How can I solve this? should I exclude some other table?
well I tried to do one simple thing to add permissions.
I've created a .json file and put in data.
[
{
"model": "auth.group",
"fields": {
"name": "foo",
"permissions": [
29,45,46,47,48 //permission ID's created in auth.group
]
}
},
{
"model": "auth.group",
"fields": {
"name": "new_grp",
"permissions": [
29,45,46,47,48
]
}
}
]
this is my initial permissions that I want to include and then
manage.py loaddata <myJsonFIle>
i think in your case it is not able to find the rows or columns in the table that's why it shows IntegrityError
Removing Group from your fixture resolves your issue
because Group depends on Permission which depends on ContentType, both of which were stripped from the export.
Judging from your comments on this question it sounds like you already figured that part out. There is another answer to you question though: Don't use fixtures for test data in Django. Django's documentation suggests you use the TestCase.setUpTestData method to setup your test data. Here's the exert from the documentation: "Tests are more readable and it’s more maintainable to create objects using the ORM."
Related
Premise:
I have a folder under the sharepoint site for e.g.
https://... <mycompany-sharepoint-site.com>/
under which we have folder so my url is something like
https://... <mycompany-sharepoint-site.com>/Documents/Sub_folder_1/Sub_folder_2
pertaining to our project.
I need to be able to create a Sharepoint list in the Sub_folder_2 - folder and not at the root level.
With Sharepoint - GraphApi - create list api url
POST https://graph.microsoft.com/v1.0/sites/{site-id}/lists
I will ONLY be able to create at the <mycompany-sharepoint-site.com> level (i.e. at the root level) which is not what I want.
FYI, I already tried (on Postman) to go with the drives//items/<folder_id> - route or I should say attempted to do so but failed.
Any help is greatly appreciated.
If you want to use Graph API to create a folder in SharePoint, please use the following query:
POST /groups/{group-id}/drive/items/{parent-item-id}/children
For more information: https://learn.microsoft.com/en-us/graph/api/driveitem-post-children?view=graph-rest-1.0&tabs=http#http-request
Hope this is helpful.
I don't think that SharePoint supports creating a list inside the folder but you can at least try to create a list and specify the path in the parent reference.
You need to find out the drive id.
POST https://graph.microsoft.com/v1.0/sites/{site_id}/lists
{
"displayName": "Test",
"columns": [
{
"name": "Column1",
"text": {}
},
{
"name": "Column2",
"number": {}
}
],
"list": {
"template": "genericList"
},
"parentReference": {
"driveType": "documentLibrary",
"driveId": "{drive_id}",
"path": "/drives/{drive_id}/root:/Documents/Sub_folder_1/Sub_folder_2"
# or
# "path": "/drives/{drive_id}/root:/Sub_folder_1/Sub_folder_2"
}
}
I don't think it's even possible at all, did you succeed that manually?
I'm trying to use Multiple Database Tables and BigQuery Multi Table Data Fusion plugin to import multiple table in one pipeline
But when I try to execute I get the following error
java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: BigQuery Multi Table has no outputs. Please check that the sink calls addOutput at some point.
I'm using Data Fusion version 6.1.4 Multiple Database Tables version 1.2.0 and BigQuery Multi Table version 0.14.8.
Any suggestion on what may be the problem?
Edit:
following the configuration of multiple table database source
{
"name": "Multiple Database Tables",
"plugin": {
"name": "MultiTableDatabase",
"type": "batchsource",
"label": "Multiple Database Tables",
"artifact": {
"name": "multi-table-plugins",
"version": "1.2.0",
"scope": "USER"
},
"properties": {
"splitsPerTable": "1",
"referenceName": "multiTable",
"connectionString": "${secure(connection)}",
"jdbcPluginName": "netezza",
"user": "${secure(username)}",
"password": "${secure(password)}",
"whiteList": "categoria_l,cliente_l,regione_l"
}
},
"outputSchema": [
{
"name": "etlSchemaBody",
"schema": ""
}
]
},
After further test the problem is that the source response is empty because data fusion is not reading view from source database but only tables
It seems like the Multiple Database Tables source produced no records ("Out 0"). I'd check there first. You can do a quick check using the Preview mode. Plugin doc here.
Related answer here.
I have a json field for a model in my Django app that typically has nested json in it. I read that to filter on a JSONfield, you would use contains on the filter for whatever value you are looking for, but I'm not getting any results back even though I know the value does exist in the JSONField. Is there an extra step I need to use for nested json in a json field?
JSON Field "Field name is Content "
"content": {
"documents": [
{
"id": "378",
"name": "Test.pdf",
"mediaFile": "http://localhost:8000/media/file.pdf"
}
]
}
Query:
document_modules =
WMDocumentModule.objects.filter(content__documents__contains={'id': "378"})
>>> document_modules: <QuerySet []>
First of all, any help with this would be amazing! I am currently trying to learn Django and am also fairly new to Python. I am trying to create a simple project management web service that could communicate using JSON with another application. All it needs to do is:
Give a list of all projects.
Give a list of all tasks for each of the projects.
Allow users to submit time for a project and task.
For models I currently have a 'Project' model and 'Task' model. I have filled the database with some dummy information. My project model has variables id, name, and description. Task just has project, task_name.
My view for task 1 above is
def api(request):
projects = Project.objects.all()#.order_by('id')
projects = serializers.serialize('json', projects, indent=2)
return HttpResponse(projects, mimetype='application/json')
associated url is url(r'^api/project/$', 'project.views.api'),
However this outputs the text below when typing
http://127.0.0.1:8000/api/project/
into the browser. Is there a better way to test JSON output? I would rather it only output the 'id' and 'name'. For some reason the id doesn't even show. This is what I put for id in models id = models.AutoField(primary_key=True). It works in the interactive shell.
[
{
"pk": 1,
"model": "project.project",
"fields": {
"name": "Project One",
"description": "This is the description for project one"
}
},
{
"pk": 2,
"model": "project.project",
"fields": {
"name": "Project Two",
"description": "This is Project Two"
}
}
]
I learn by example so if someone could show me how this should be done I would be extremely grateful!
By the way for outputting the list of tasks, I was thinking the url would be something like:
http://127.0.0.1:8000/api/project/?project_name
but I'm not sure how to handle that in the view.
I am using the method described in this question to load intial users for my django project.
This saves user permissions, where one permission record might look like this:
{
"pk": 56,
"model": "auth.permission",
"fields": {
"codename": "change_somemodel",
"name": "Can change some model",
"content_type": 19
}
And a user record:
{
"pk": 2,
"model": "auth.user",
"fields": {
"username": "some_user",
"first_name": "",
"last_name": "",
"is_active": true,
"is_superuser": false,
"is_staff": true,
"last_login": "2011-09-20 06:36:54",
"groups": [],
"user_permissions": [
10,
11,
19,
20,
21,
1,
2,
56,
...,
],
"password": "sha1$e4f29$fcec7f8bb930d98abdaaa3c0020220f413c4c1f5",
"email": "",
"date_joined": "2011-03-15 06:01:41"
}
Is there any potential for the content type foreign key to change on a future installation? How about if models or apps added? For example, let's say I add a model to my core app, then I have some reusable apps which are listed after that in settings.py, will those have a different content_type_id on a new installation? Can I include the content_type table in my initial data, or is that likely to cause other issues?
If this isn't a reliable method to load multiple initial users into the database, what are the alternatives?
Check Natural Keys
. Use -n w/ dumpdata, like ./manage.py dumpdata -n auth.User
In practice, it may be that you also have to exclude contenttypes to make this work. Additionally, if you have any user or group data, you'll need to dump those as well. See this thread for more info on excluding contenttypes.
For my app, I had to use the following command for loaddata or test to work with the fixtures generated by manage.py dumpdata. Additionally, you should probably use --indent N option to make sure that you get a human readable file (where N is the number of spaces for indentation)
./manage.py dumpdata -n --indent 4 -e contenttypes appName auth.Group auth.User > initial_data.json